dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 7 | #ifndef FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |
| 8 | #define FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 10 | #include <memory> |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 11 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/include/cpdf_occontext.h" |
tsepez | 55be02e | 2016-09-12 11:21:42 -0700 | [diff] [blame] | 15 | #include "core/fxcrt/include/cfx_observable.h" |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cfx_systemhandler.h" |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 17 | #include "fpdfsdk/include/fsdk_define.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 18 | #include "public/fpdf_formfill.h" |
Dan Sinclair | df5a116 | 2016-03-09 16:51:34 -0500 | [diff] [blame] | 19 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 20 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | class CFFL_IFormFiller; |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 22 | class CFX_SystemHandler; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 23 | class CPDFSDK_ActionHandler; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 24 | class CPDFSDK_AnnotHandlerMgr; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 25 | class CPDFSDK_Document; |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 26 | class IJS_Runtime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 28 | class CPDFSDK_Environment final { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | public: |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 30 | CPDFSDK_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); |
| 31 | ~CPDFSDK_Environment(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | 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 Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 67 | FX_SYSTEMTIME FFI_GetLocalTime() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 79 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | return fxtime; |
| 81 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | void FFI_OnChange() { |
| 84 | if (m_pInfo && m_pInfo->FFI_OnChange) |
| 85 | m_pInfo->FFI_OnChange(m_pInfo); |
| 86 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 88 | FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; |
| 90 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 92 | FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; |
| 94 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 95 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 96 | FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | return (nFlag & FWL_EVENTFLAG_AltKey) != 0; |
| 98 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | 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); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 103 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { |
| 107 | if (m_pInfo && m_pInfo->FFI_GetCurrentPage) |
| 108 | return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 109 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | } |
Tom Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | 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 Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | 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 Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 130 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | 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 Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 135 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 144 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 145 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) { |
Jun Fang | 01fe588 | 2015-11-25 11:05:58 +0800 | [diff] [blame] | 158 | if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) { |
| 159 | return -1; |
| 160 | } |
| 161 | return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 163 | |
Jun Fang | 01fe588 | 2015-11-25 11:05:58 +0800 | [diff] [blame] | 164 | void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | if (m_pInfo && m_pInfo->FFI_SetCurrentPage) |
| 166 | m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 168 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | CFX_WideString FFI_GetPlatform() { |
| 172 | if (m_pInfo && m_pInfo->FFI_GetPlatform) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 173 | int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | if (nRequiredLen <= 0) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 175 | return L""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 176 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | char* pbuff = new char[nRequiredLen]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 182 | return L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | } |
| 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 190 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | return L""; |
| 192 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 193 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 202 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 217 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 219 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | 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); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 263 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | } |
| 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 Zhang | db5256f | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 282 | return new CFPDF_FileStream(fileHandler); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | } |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 284 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | } |
| 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 | |
thestig | 77d148d | 2016-04-06 06:28:31 -0700 | [diff] [blame] | 313 | FPDF_BSTR response; |
| 314 | FPDF_BStr_Init(&response); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, |
thestig | 77d148d | 2016-04-06 06:28:31 -0700 | [diff] [blame] | 316 | header, &response); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | |
| 318 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
thestig | 77d148d | 2016-04-06 06:28:31 -0700 | [diff] [blame] | 319 | (unsigned short*)response.str, response.len / sizeof(unsigned short)); |
| 320 | FPDF_BStr_Clear(&response); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | |
| 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 Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | CFX_WideString FFI_GetLanguage() { |
| 348 | if (m_pInfo && m_pInfo->FFI_GetLanguage) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 349 | int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | if (nRequiredLen <= 0) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 351 | return L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | |
| 353 | char* pbuff = new char[nRequiredLen]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | 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 Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 366 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | return L""; |
| 368 | } |
Lei Zhang | 84e5a12 | 2016-02-19 14:25:10 -0800 | [diff] [blame] | 369 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 370 | void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const { |
Lei Zhang | 84e5a12 | 2016-02-19 14:25:10 -0800 | [diff] [blame] | 371 | if (m_pInfo && m_pInfo->FFI_PageEvent) |
jinming_wang | a1cef70 | 2016-03-18 16:35:40 +0800 | [diff] [blame] | 372 | m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); |
Jun Fang | c30d5bf | 2016-02-02 18:12:23 -0800 | [diff] [blame] | 373 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 374 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 375 | |
Tom Sepez | 5702859 | 2016-02-01 15:49:11 -0800 | [diff] [blame] | 376 | 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 Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 409 | 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 Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 412 | UnderlyingDocumentType* GetUnderlyingDocument() const { |
| 413 | return m_pUnderlyingDoc; |
| 414 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | CFX_ByteString GetAppName() const { return ""; } |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 416 | CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 418 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. |
| 420 | CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 421 | IJS_Runtime* GetJSRuntime(); // Creates if not present. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 422 | CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 423 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | private: |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 425 | std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr; |
| 426 | std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; |
| 427 | std::unique_ptr<IJS_Runtime> m_pJSRuntime; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | FPDF_FORMFILLINFO* const m_pInfo; |
| 429 | CPDFSDK_Document* m_pSDKDoc; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 430 | UnderlyingDocumentType* const m_pUnderlyingDoc; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 431 | std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller; |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 432 | std::unique_ptr<CFX_SystemHandler> m_pSysHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 433 | }; |
| 434 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame^] | 435 | #endif // FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |