blob: 7fd146a043bace5162ae5a1eb46c7986e57e8a2b [file] [log] [blame]
dsinclairf34518b2016-09-13 12:03:48 -07001// Copyright 2016 PDFium Authors. All rights reserved.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair79db6092016-09-14 07:27:21 -07007#ifndef FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_
8#define FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080010#include <memory>
Lei Zhang606346f2015-06-19 18:11:07 -070011
tsepez1e2c5572016-05-25 14:58:09 -070012#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040013#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
dsinclaircac704d2016-07-28 12:59:09 -070014#include "core/fpdfdoc/include/cpdf_occontext.h"
tsepez55be02e2016-09-12 11:21:42 -070015#include "core/fxcrt/include/cfx_observable.h"
dsinclairb9590102016-04-27 06:38:59 -070016#include "fpdfsdk/cfx_systemhandler.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050017#include "fpdfsdk/include/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080018#include "public/fpdf_formfill.h"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050019#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080020
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021class CFFL_IFormFiller;
dsinclairb9590102016-04-27 06:38:59 -070022class CFX_SystemHandler;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070023class CPDFSDK_ActionHandler;
jaepark98e10192016-08-15 10:51:11 -070024class CPDFSDK_AnnotHandlerMgr;
dsinclairf34518b2016-09-13 12:03:48 -070025class CPDFSDK_Document;
dsinclair64376be2016-03-31 20:03:24 -070026class IJS_Runtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
dsinclair79db6092016-09-14 07:27:21 -070028class CPDFSDK_Environment final {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 public:
dsinclair79db6092016-09-14 07:27:21 -070030 CPDFSDK_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
31 ~CPDFSDK_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 void FFI_Invalidate(FPDF_PAGE page,
34 double left,
35 double top,
36 double right,
37 double bottom) {
38 if (m_pInfo && m_pInfo->FFI_Invalidate)
39 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
40 }
41
42 void FFI_OutputSelectedRect(FPDF_PAGE page,
43 double left,
44 double top,
45 double right,
46 double bottom) {
47 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
48 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
49 }
50
51 void FFI_SetCursor(int nCursorType) {
52 if (m_pInfo && m_pInfo->FFI_SetCursor)
53 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
54 }
55
56 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
57 if (m_pInfo && m_pInfo->FFI_SetTimer)
58 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
59 return -1;
60 }
61
62 void FFI_KillTimer(int nTimerID) {
63 if (m_pInfo && m_pInfo->FFI_KillTimer)
64 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
65 }
66
Tom Sepez468e5892015-10-13 15:49:36 -070067 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 FX_SYSTEMTIME fxtime;
69 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
70 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
71 fxtime.wDay = systime.wDay;
72 fxtime.wDayOfWeek = systime.wDayOfWeek;
73 fxtime.wHour = systime.wHour;
74 fxtime.wMilliseconds = systime.wMilliseconds;
75 fxtime.wMinute = systime.wMinute;
76 fxtime.wMonth = systime.wMonth;
77 fxtime.wSecond = systime.wSecond;
78 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070079 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 return fxtime;
81 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 void FFI_OnChange() {
84 if (m_pInfo && m_pInfo->FFI_OnChange)
85 m_pInfo->FFI_OnChange(m_pInfo);
86 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
tsepezc3255f52016-03-25 14:52:27 -070088 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
90 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
tsepezc3255f52016-03-25 14:52:27 -070092 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
94 }
Tom Sepezc6ab1722015-02-05 15:27:25 -080095
tsepezc3255f52016-03-25 14:52:27 -070096 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
98 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
101 if (m_pInfo && m_pInfo->FFI_GetPage)
102 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
thestig1cd352e2016-06-07 17:53:06 -0700103 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
107 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
108 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
thestig1cd352e2016-06-07 17:53:06 -0700109 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 int FFI_GetRotation(FPDF_PAGE page) {
113 if (m_pInfo && m_pInfo->FFI_GetRotation)
114 return m_pInfo->FFI_GetRotation(m_pInfo, page);
115 return 0;
116 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
119 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
120 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
121 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 void FFI_OnSetFieldInputFocus(void* field,
124 FPDF_WIDESTRING focusText,
125 FPDF_DWORD nTextLen,
126 FX_BOOL bFocus) {
127 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
128 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
129 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 void FFI_DoURIAction(const FX_CHAR* bsURI) {
132 if (m_pInfo && m_pInfo->FFI_DoURIAction)
133 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
134 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136 void FFI_DoGoToAction(int nPageIndex,
137 int zoomMode,
138 float* fPosArray,
139 int sizeOfArray) {
140 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
141 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
142 sizeOfArray);
143 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
Tom Sepez51da0932015-11-25 16:05:49 -0800145#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 void FFI_DisplayCaret(FPDF_PAGE page,
147 FPDF_BOOL bVisible,
148 double left,
149 double top,
150 double right,
151 double bottom) {
152 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
153 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
154 bottom);
155 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800158 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
159 return -1;
160 }
161 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Jun Fang01fe5882015-11-25 11:05:58 +0800164 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
166 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 CFX_WideString FFI_GetPlatform() {
172 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
thestig1cd352e2016-06-07 17:53:06 -0700173 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700175 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 memset(pbuff, 0, nRequiredLen);
179 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
180 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
181 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700182 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 }
184 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
185 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
186 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
187 bsRet.GetLength() / sizeof(unsigned short));
188 delete[] pbuff;
189 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700190 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 return L"";
192 }
Bo Xufdc00a72014-10-28 23:03:33 -0700193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 void FFI_GotoURL(FPDF_DOCUMENT document,
195 const CFX_WideStringC& wsURL,
196 FX_BOOL bAppend) {
197 if (m_pInfo && m_pInfo->FFI_GotoURL) {
198 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
199 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
200 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
201 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700202 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 }
Bo Xufdc00a72014-10-28 23:03:33 -0700204
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
206 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
207 double left;
208 double top;
209 double right;
210 double bottom;
211 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
212
213 dstRect.left = static_cast<float>(left);
214 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
215 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
216 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700217 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 }
Bo Xufdc00a72014-10-28 23:03:33 -0700219
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
221 FPDF_WIDGET hWidget,
222 int menuFlag,
223 CFX_PointF ptPopup,
224 const CFX_PointF* pRectExclude) {
225 if (m_pInfo && m_pInfo->FFI_PopupMenu)
226 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
227 ptPopup.y);
228 return FALSE;
229 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 void FFI_Alert(FPDF_WIDESTRING Msg,
232 FPDF_WIDESTRING Title,
233 int Type,
234 int Icon) {
235 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
236 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
237 Type, Icon);
238 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
241 FPDF_WIDESTRING pTo,
242 FPDF_WIDESTRING pSubject,
243 FPDF_WIDESTRING pCC,
244 FPDF_WIDESTRING pBcc,
245 FPDF_WIDESTRING pMsg) {
246 if (m_pInfo && m_pInfo->FFI_EmailTo)
247 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
248 pMsg);
249 }
250
251 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
252 int fileFlag,
253 FPDF_WIDESTRING uploadTo) {
254 if (m_pInfo && m_pInfo->FFI_UploadTo)
255 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
256 }
257
258 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
259 FPDF_WIDESTRING wsURL,
260 const char* mode) {
261 if (m_pInfo && m_pInfo->FFI_OpenFile)
262 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
thestig1cd352e2016-06-07 17:53:06 -0700263 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 }
265
266 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
267 return L"";
268 }
269
270 int FFI_GetDocumentCount() const { return 0; }
271 int FFI_GetCurDocument() const { return 0; }
272
273 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
274 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
275 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
276 FPDF_WIDESTRING wsURL =
277 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
278
279 FPDF_LPFILEHANDLER fileHandler =
280 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
281
Lei Zhangdb5256f2015-10-02 10:11:43 -0700282 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 }
thestig1cd352e2016-06-07 17:53:06 -0700284 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 }
286
287 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
288 const FX_WCHAR* wsData,
289 const FX_WCHAR* wsContentType,
290 const FX_WCHAR* wsEncode,
291 const FX_WCHAR* wsHeader) {
292 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
293 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
294 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
295
296 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
297 FPDF_WIDESTRING data =
298 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
299
300 CFX_ByteString bsContentType =
301 CFX_WideString(wsContentType).UTF16LE_Encode();
302 FPDF_WIDESTRING contentType =
303 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
304
305 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
306 FPDF_WIDESTRING encode =
307 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
308
309 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
310 FPDF_WIDESTRING header =
311 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
312
thestig77d148d2016-04-06 06:28:31 -0700313 FPDF_BSTR response;
314 FPDF_BStr_Init(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
thestig77d148d2016-04-06 06:28:31 -0700316 header, &response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317
318 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
thestig77d148d2016-04-06 06:28:31 -0700319 (unsigned short*)response.str, response.len / sizeof(unsigned short));
320 FPDF_BStr_Clear(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321
322 return wsRet;
323 }
324 return L"";
325 }
326
327 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
328 const FX_WCHAR* wsData,
329 const FX_WCHAR* wsEncode) {
330 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
331 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
332 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
333
334 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
335 FPDF_WIDESTRING data =
336 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
337
338 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
339 FPDF_WIDESTRING encode =
340 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
341
342 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
343 }
344 return FALSE;
345 }
346
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 CFX_WideString FFI_GetLanguage() {
348 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
thestig1cd352e2016-06-07 17:53:06 -0700349 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700351 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352
353 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 memset(pbuff, 0, nRequiredLen);
355 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
356 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
357 delete[] pbuff;
358 return L"";
359 }
360 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
361 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
362 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
363 bsRet.GetLength() / sizeof(unsigned short));
364 delete[] pbuff;
365 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700366 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 return L"";
368 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800369
tsepezc3255f52016-03-25 14:52:27 -0700370 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const {
Lei Zhang84e5a122016-02-19 14:25:10 -0800371 if (m_pInfo && m_pInfo->FFI_PageEvent)
jinming_wanga1cef702016-03-18 16:35:40 +0800372 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800373 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800374#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375
Tom Sepez57028592016-02-01 15:49:11 -0800376 int JS_appAlert(const FX_WCHAR* Msg,
377 const FX_WCHAR* Title,
378 FX_UINT Type,
379 FX_UINT Icon);
380 int JS_appResponse(const FX_WCHAR* Question,
381 const FX_WCHAR* Title,
382 const FX_WCHAR* Default,
383 const FX_WCHAR* cLabel,
384 FPDF_BOOL bPassword,
385 void* response,
386 int length);
387 void JS_appBeep(int nType);
388 CFX_WideString JS_fieldBrowse();
389 CFX_WideString JS_docGetFilePath();
390 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
391 void JS_docmailForm(void* mailData,
392 int length,
393 FPDF_BOOL bUI,
394 const FX_WCHAR* To,
395 const FX_WCHAR* Subject,
396 const FX_WCHAR* CC,
397 const FX_WCHAR* BCC,
398 const FX_WCHAR* Msg);
399 void JS_docprint(FPDF_BOOL bUI,
400 int nStart,
401 int nEnd,
402 FPDF_BOOL bSilent,
403 FPDF_BOOL bShrinkToFit,
404 FPDF_BOOL bPrintAsImage,
405 FPDF_BOOL bReverse,
406 FPDF_BOOL bAnnotations);
407 void JS_docgotoPage(int nPageNum);
408
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
410 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
411 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800412 UnderlyingDocumentType* GetUnderlyingDocument() const {
413 return m_pUnderlyingDoc;
414 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700416 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700418
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
420 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700421 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800423
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800425 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
426 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
427 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 FPDF_FORMFILLINFO* const m_pInfo;
429 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800430 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800431 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700432 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700433};
434
dsinclair79db6092016-09-14 07:27:21 -0700435#endif // FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_