dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 7 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 8 | |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 11 | #include "fpdfsdk/cpdfsdk_annothandlermgr.h" |
| 12 | #include "fpdfsdk/cpdfsdk_document.h" |
dsinclair | b94d7c9 | 2016-09-21 12:07:00 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/fsdk_actionhandler.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/javascript/ijs_runtime.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 16 | #include "third_party/base/ptr_util.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef PDF_ENABLE_XFA |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 20 | #endif // PDF_ENABLE_XFA |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | // NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken |
| 25 | // since modifying the result would impact |bsUTF16LE|. |
| 26 | FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { |
| 27 | return reinterpret_cast<FPDF_WIDESTRING>( |
| 28 | bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); |
| 29 | } |
| 30 | |
| 31 | } // namespace |
| 32 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 33 | CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( |
| 34 | UnderlyingDocumentType* pDoc, |
| 35 | FPDF_FORMFILLINFO* pFFinfo) |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 36 | : m_pInfo(pFFinfo), |
| 37 | m_pSDKDoc(new CPDFSDK_Document(pDoc, this)), |
| 38 | m_pUnderlyingDoc(pDoc), |
| 39 | m_pSysHandler(new CFX_SystemHandler(this)) {} |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 40 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 41 | CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 42 | #ifdef PDF_ENABLE_XFA |
| 43 | CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 44 | if (pProvider->m_pEnvList.GetSize() == 0) |
| 45 | pProvider->SetJavaScriptInitialized(FALSE); |
| 46 | #endif // PDF_ENABLE_XFA |
| 47 | if (m_pInfo && m_pInfo->Release) |
| 48 | m_pInfo->Release(m_pInfo); |
| 49 | } |
| 50 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 51 | int CPDFSDK_FormFillEnvironment::JS_appAlert(const FX_WCHAR* Msg, |
| 52 | const FX_WCHAR* Title, |
| 53 | uint32_t Type, |
| 54 | uint32_t Icon) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 55 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 56 | !m_pInfo->m_pJsPlatform->app_alert) { |
| 57 | return -1; |
| 58 | } |
| 59 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 60 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 61 | return m_pInfo->m_pJsPlatform->app_alert( |
| 62 | m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsMsg), |
| 63 | AsFPDFWideString(&bsTitle), Type, Icon); |
| 64 | } |
| 65 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 66 | int CPDFSDK_FormFillEnvironment::JS_appResponse(const FX_WCHAR* Question, |
| 67 | const FX_WCHAR* Title, |
| 68 | const FX_WCHAR* Default, |
| 69 | const FX_WCHAR* cLabel, |
| 70 | FPDF_BOOL bPassword, |
| 71 | void* response, |
| 72 | int length) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 73 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 74 | !m_pInfo->m_pJsPlatform->app_response) { |
| 75 | return -1; |
| 76 | } |
| 77 | CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); |
| 78 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 79 | CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); |
| 80 | CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); |
| 81 | return m_pInfo->m_pJsPlatform->app_response( |
| 82 | m_pInfo->m_pJsPlatform, AsFPDFWideString(&bsQuestion), |
| 83 | AsFPDFWideString(&bsTitle), AsFPDFWideString(&bsDefault), |
| 84 | AsFPDFWideString(&bsLabel), bPassword, response, length); |
| 85 | } |
| 86 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 87 | void CPDFSDK_FormFillEnvironment::JS_appBeep(int nType) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 88 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 89 | !m_pInfo->m_pJsPlatform->app_beep) { |
| 90 | return; |
| 91 | } |
| 92 | m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); |
| 93 | } |
| 94 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 95 | CFX_WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 96 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 97 | !m_pInfo->m_pJsPlatform->Field_browse) { |
| 98 | return CFX_WideString(); |
| 99 | } |
| 100 | const int nRequiredLen = |
| 101 | m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); |
| 102 | if (nRequiredLen <= 0) |
| 103 | return CFX_WideString(); |
| 104 | |
| 105 | std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 106 | memset(pBuff.get(), 0, nRequiredLen); |
| 107 | const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 108 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 109 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 110 | return CFX_WideString(); |
| 111 | |
| 112 | return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); |
| 113 | } |
| 114 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 115 | CFX_WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 116 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 117 | !m_pInfo->m_pJsPlatform->Doc_getFilePath) { |
| 118 | return CFX_WideString(); |
| 119 | } |
| 120 | const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 121 | m_pInfo->m_pJsPlatform, nullptr, 0); |
| 122 | if (nRequiredLen <= 0) |
| 123 | return CFX_WideString(); |
| 124 | |
| 125 | std::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 126 | memset(pBuff.get(), 0, nRequiredLen); |
| 127 | const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 128 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 129 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 130 | return CFX_WideString(); |
| 131 | |
| 132 | return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen)); |
| 133 | } |
| 134 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 135 | void CPDFSDK_FormFillEnvironment::JS_docSubmitForm(void* formData, |
| 136 | int length, |
| 137 | const FX_WCHAR* URL) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 138 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 139 | !m_pInfo->m_pJsPlatform->Doc_submitForm) { |
| 140 | return; |
| 141 | } |
| 142 | CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); |
| 143 | m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, |
| 144 | length, |
| 145 | AsFPDFWideString(&bsDestination)); |
| 146 | } |
| 147 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 148 | void CPDFSDK_FormFillEnvironment::JS_docmailForm(void* mailData, |
| 149 | int length, |
| 150 | FPDF_BOOL bUI, |
| 151 | const FX_WCHAR* To, |
| 152 | const FX_WCHAR* Subject, |
| 153 | const FX_WCHAR* CC, |
| 154 | const FX_WCHAR* BCC, |
| 155 | const FX_WCHAR* Msg) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 156 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 157 | !m_pInfo->m_pJsPlatform->Doc_mail) { |
| 158 | return; |
| 159 | } |
| 160 | CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); |
| 161 | CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); |
| 162 | CFX_ByteString bsCC = CFX_WideString(CC).UTF16LE_Encode(); |
| 163 | CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); |
| 164 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 165 | m_pInfo->m_pJsPlatform->Doc_mail( |
| 166 | m_pInfo->m_pJsPlatform, mailData, length, bUI, AsFPDFWideString(&bsTo), |
| 167 | AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC), |
| 168 | AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg)); |
| 169 | } |
| 170 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 171 | void CPDFSDK_FormFillEnvironment::JS_docprint(FPDF_BOOL bUI, |
| 172 | int nStart, |
| 173 | int nEnd, |
| 174 | FPDF_BOOL bSilent, |
| 175 | FPDF_BOOL bShrinkToFit, |
| 176 | FPDF_BOOL bPrintAsImage, |
| 177 | FPDF_BOOL bReverse, |
| 178 | FPDF_BOOL bAnnotations) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 179 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 180 | !m_pInfo->m_pJsPlatform->Doc_print) { |
| 181 | return; |
| 182 | } |
| 183 | m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, |
| 184 | bSilent, bShrinkToFit, bPrintAsImage, |
| 185 | bReverse, bAnnotations); |
| 186 | } |
| 187 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 188 | void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 189 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 190 | !m_pInfo->m_pJsPlatform->Doc_gotoPage) { |
| 191 | return; |
| 192 | } |
| 193 | m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); |
| 194 | } |
| 195 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 196 | IJS_Runtime* CPDFSDK_FormFillEnvironment::GetJSRuntime() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 197 | if (!IsJSInitiated()) |
| 198 | return nullptr; |
| 199 | if (!m_pJSRuntime) |
| 200 | m_pJSRuntime.reset(IJS_Runtime::Create(this)); |
| 201 | return m_pJSRuntime.get(); |
| 202 | } |
| 203 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 204 | CPDFSDK_AnnotHandlerMgr* CPDFSDK_FormFillEnvironment::GetAnnotHandlerMgr() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 205 | if (!m_pAnnotHandlerMgr) |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 206 | m_pAnnotHandlerMgr = pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>(this); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 207 | return m_pAnnotHandlerMgr.get(); |
| 208 | } |
| 209 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 210 | CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHander() { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 211 | if (!m_pActionHandler) |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 212 | m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 213 | return m_pActionHandler.get(); |
| 214 | } |
| 215 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 216 | CFFL_InteractiveFormFiller* |
| 217 | CPDFSDK_FormFillEnvironment::GetInteractiveFormFiller() { |
dsinclair | b94d7c9 | 2016-09-21 12:07:00 -0700 | [diff] [blame] | 218 | if (!m_pFormFiller) |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 219 | m_pFormFiller = pdfium::MakeUnique<CFFL_InteractiveFormFiller>(this); |
dsinclair | b94d7c9 | 2016-09-21 12:07:00 -0700 | [diff] [blame] | 220 | return m_pFormFiller.get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 221 | } |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 222 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 223 | void CPDFSDK_FormFillEnvironment::Invalidate(FPDF_PAGE page, |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 224 | double left, |
| 225 | double top, |
| 226 | double right, |
| 227 | double bottom) { |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 228 | if (m_pInfo && m_pInfo->FFI_Invalidate) |
| 229 | m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); |
| 230 | } |
| 231 | |
| 232 | void CPDFSDK_FormFillEnvironment::OutputSelectedRect(FPDF_PAGE page, |
| 233 | double left, |
| 234 | double top, |
| 235 | double right, |
| 236 | double bottom) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 237 | if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) |
| 238 | m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); |
| 239 | } |
| 240 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 241 | void CPDFSDK_FormFillEnvironment::SetCursor(int nCursorType) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 242 | if (m_pInfo && m_pInfo->FFI_SetCursor) |
| 243 | m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); |
| 244 | } |
| 245 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 246 | int CPDFSDK_FormFillEnvironment::SetTimer(int uElapse, |
| 247 | TimerCallback lpTimerFunc) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 248 | if (m_pInfo && m_pInfo->FFI_SetTimer) |
| 249 | return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); |
| 250 | return -1; |
| 251 | } |
| 252 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 253 | void CPDFSDK_FormFillEnvironment::KillTimer(int nTimerID) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 254 | if (m_pInfo && m_pInfo->FFI_KillTimer) |
| 255 | m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); |
| 256 | } |
| 257 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 258 | FX_SYSTEMTIME CPDFSDK_FormFillEnvironment::GetLocalTime() const { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 259 | FX_SYSTEMTIME fxtime; |
| 260 | if (!m_pInfo || !m_pInfo->FFI_GetLocalTime) |
| 261 | return fxtime; |
| 262 | |
| 263 | FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); |
| 264 | fxtime.wDay = systime.wDay; |
| 265 | fxtime.wDayOfWeek = systime.wDayOfWeek; |
| 266 | fxtime.wHour = systime.wHour; |
| 267 | fxtime.wMilliseconds = systime.wMilliseconds; |
| 268 | fxtime.wMinute = systime.wMinute; |
| 269 | fxtime.wMonth = systime.wMonth; |
| 270 | fxtime.wSecond = systime.wSecond; |
| 271 | fxtime.wYear = systime.wYear; |
| 272 | return fxtime; |
| 273 | } |
| 274 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 275 | void CPDFSDK_FormFillEnvironment::OnChange() { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 276 | if (m_pInfo && m_pInfo->FFI_OnChange) |
| 277 | m_pInfo->FFI_OnChange(m_pInfo); |
| 278 | } |
| 279 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 280 | FX_BOOL CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(uint32_t nFlag) const { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 281 | return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; |
| 282 | } |
| 283 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 284 | FX_BOOL CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(uint32_t nFlag) const { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 285 | return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; |
| 286 | } |
| 287 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 288 | FX_BOOL CPDFSDK_FormFillEnvironment::IsALTKeyDown(uint32_t nFlag) const { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 289 | return (nFlag & FWL_EVENTFLAG_AltKey) != 0; |
| 290 | } |
| 291 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 292 | FPDF_PAGE CPDFSDK_FormFillEnvironment::GetPage(FPDF_DOCUMENT document, |
| 293 | int nPageIndex) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 294 | if (m_pInfo && m_pInfo->FFI_GetPage) |
| 295 | return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); |
| 296 | return nullptr; |
| 297 | } |
| 298 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 299 | FPDF_PAGE CPDFSDK_FormFillEnvironment::GetCurrentPage(FPDF_DOCUMENT document) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 300 | if (m_pInfo && m_pInfo->FFI_GetCurrentPage) |
| 301 | return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); |
| 302 | return nullptr; |
| 303 | } |
| 304 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 305 | void CPDFSDK_FormFillEnvironment::ExecuteNamedAction( |
| 306 | const FX_CHAR* namedAction) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 307 | if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) |
| 308 | m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); |
| 309 | } |
| 310 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 311 | void CPDFSDK_FormFillEnvironment::OnSetFieldInputFocus( |
| 312 | FPDF_WIDESTRING focusText, |
| 313 | FPDF_DWORD nTextLen, |
| 314 | FX_BOOL bFocus) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 315 | if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) |
| 316 | m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); |
| 317 | } |
| 318 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 319 | void CPDFSDK_FormFillEnvironment::DoURIAction(const FX_CHAR* bsURI) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 320 | if (m_pInfo && m_pInfo->FFI_DoURIAction) |
| 321 | m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); |
| 322 | } |
| 323 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 324 | void CPDFSDK_FormFillEnvironment::DoGoToAction(int nPageIndex, |
| 325 | int zoomMode, |
| 326 | float* fPosArray, |
| 327 | int sizeOfArray) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 328 | if (m_pInfo && m_pInfo->FFI_DoGoToAction) { |
| 329 | m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, |
| 330 | sizeOfArray); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | #ifdef PDF_ENABLE_XFA |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 335 | void CPDFSDK_FormFillEnvironment::DisplayCaret(FPDF_PAGE page, |
| 336 | FPDF_BOOL bVisible, |
| 337 | double left, |
| 338 | double top, |
| 339 | double right, |
| 340 | double bottom) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 341 | if (m_pInfo && m_pInfo->FFI_DisplayCaret) { |
| 342 | m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, |
| 343 | bottom); |
| 344 | } |
| 345 | } |
| 346 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 347 | int CPDFSDK_FormFillEnvironment::GetCurrentPageIndex(FPDF_DOCUMENT document) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 348 | if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) |
| 349 | return -1; |
| 350 | return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); |
| 351 | } |
| 352 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 353 | void CPDFSDK_FormFillEnvironment::SetCurrentPage(FPDF_DOCUMENT document, |
| 354 | int iCurPage) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 355 | if (m_pInfo && m_pInfo->FFI_SetCurrentPage) |
| 356 | m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); |
| 357 | } |
| 358 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 359 | CFX_WideString CPDFSDK_FormFillEnvironment::GetPlatform() { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 360 | if (!m_pInfo || !m_pInfo->FFI_GetPlatform) |
| 361 | return L""; |
| 362 | |
| 363 | int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); |
| 364 | if (nRequiredLen <= 0) |
| 365 | return L""; |
| 366 | |
| 367 | char* pbuff = new char[nRequiredLen]; |
| 368 | memset(pbuff, 0, nRequiredLen); |
| 369 | int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); |
| 370 | if (nActualLen <= 0 || nActualLen > nRequiredLen) { |
| 371 | delete[] pbuff; |
| 372 | return L""; |
| 373 | } |
| 374 | CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); |
| 375 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 376 | (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), |
| 377 | bsRet.GetLength() / sizeof(unsigned short)); |
| 378 | delete[] pbuff; |
| 379 | return wsRet; |
| 380 | } |
| 381 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 382 | void CPDFSDK_FormFillEnvironment::GotoURL(FPDF_DOCUMENT document, |
| 383 | const CFX_WideStringC& wsURL) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 384 | if (!m_pInfo || !m_pInfo->FFI_GotoURL) |
| 385 | return; |
| 386 | |
| 387 | CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 388 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); |
| 389 | m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); |
| 390 | bsTo.ReleaseBuffer(); |
| 391 | } |
| 392 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 393 | void CPDFSDK_FormFillEnvironment::GetPageViewRect(FPDF_PAGE page, |
| 394 | FS_RECTF& dstRect) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 395 | if (!m_pInfo || !m_pInfo->FFI_GetPageViewRect) |
| 396 | return; |
| 397 | |
| 398 | double left; |
| 399 | double top; |
| 400 | double right; |
| 401 | double bottom; |
| 402 | m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); |
| 403 | |
| 404 | dstRect.left = static_cast<float>(left); |
| 405 | dstRect.top = static_cast<float>(top < bottom ? bottom : top); |
| 406 | dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); |
| 407 | dstRect.right = static_cast<float>(right); |
| 408 | } |
| 409 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 410 | FX_BOOL CPDFSDK_FormFillEnvironment::PopupMenu(FPDF_PAGE page, |
| 411 | FPDF_WIDGET hWidget, |
| 412 | int menuFlag, |
| 413 | CFX_PointF pt) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 414 | if (!m_pInfo || !m_pInfo->FFI_PopupMenu) |
| 415 | return FALSE; |
| 416 | return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y); |
| 417 | } |
| 418 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 419 | void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg, |
| 420 | FPDF_WIDESTRING Title, |
| 421 | int Type, |
| 422 | int Icon) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 423 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { |
| 424 | m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, |
| 425 | Icon); |
| 426 | } |
| 427 | } |
| 428 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 429 | void CPDFSDK_FormFillEnvironment::EmailTo(FPDF_FILEHANDLER* fileHandler, |
| 430 | FPDF_WIDESTRING pTo, |
| 431 | FPDF_WIDESTRING pSubject, |
| 432 | FPDF_WIDESTRING pCC, |
| 433 | FPDF_WIDESTRING pBcc, |
| 434 | FPDF_WIDESTRING pMsg) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 435 | if (m_pInfo && m_pInfo->FFI_EmailTo) |
| 436 | m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg); |
| 437 | } |
| 438 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 439 | void CPDFSDK_FormFillEnvironment::UploadTo(FPDF_FILEHANDLER* fileHandler, |
| 440 | int fileFlag, |
| 441 | FPDF_WIDESTRING uploadTo) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 442 | if (m_pInfo && m_pInfo->FFI_UploadTo) |
| 443 | m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); |
| 444 | } |
| 445 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 446 | FPDF_FILEHANDLER* CPDFSDK_FormFillEnvironment::OpenFile(int fileType, |
| 447 | FPDF_WIDESTRING wsURL, |
| 448 | const char* mode) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 449 | if (m_pInfo && m_pInfo->FFI_OpenFile) |
| 450 | return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); |
| 451 | return nullptr; |
| 452 | } |
| 453 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 454 | IFX_FileRead* CPDFSDK_FormFillEnvironment::DownloadFromURL( |
| 455 | const FX_WCHAR* url) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 456 | if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL) |
| 457 | return nullptr; |
| 458 | |
| 459 | CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); |
| 460 | FPDF_WIDESTRING wsURL = |
| 461 | (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); |
| 462 | |
| 463 | FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); |
| 464 | |
| 465 | return new CFPDF_FileStream(fileHandler); |
| 466 | } |
| 467 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 468 | CFX_WideString CPDFSDK_FormFillEnvironment::PostRequestURL( |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 469 | const FX_WCHAR* wsURL, |
| 470 | const FX_WCHAR* wsData, |
| 471 | const FX_WCHAR* wsContentType, |
| 472 | const FX_WCHAR* wsEncode, |
| 473 | const FX_WCHAR* wsHeader) { |
| 474 | if (!m_pInfo || !m_pInfo->FFI_PostRequestURL) |
| 475 | return L""; |
| 476 | |
| 477 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 478 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 479 | |
| 480 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 481 | FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 482 | |
| 483 | CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode(); |
| 484 | FPDF_WIDESTRING contentType = |
| 485 | (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); |
| 486 | |
| 487 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 488 | FPDF_WIDESTRING encode = |
| 489 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 490 | |
| 491 | CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); |
| 492 | FPDF_WIDESTRING header = |
| 493 | (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); |
| 494 | |
| 495 | FPDF_BSTR response; |
| 496 | FPDF_BStr_Init(&response); |
| 497 | m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header, |
| 498 | &response); |
| 499 | |
| 500 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 501 | (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING)); |
| 502 | FPDF_BStr_Clear(&response); |
| 503 | |
| 504 | return wsRet; |
| 505 | } |
| 506 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 507 | FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const FX_WCHAR* wsURL, |
| 508 | const FX_WCHAR* wsData, |
| 509 | const FX_WCHAR* wsEncode) { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 510 | if (!m_pInfo || !m_pInfo->FFI_PutRequestURL) |
| 511 | return FALSE; |
| 512 | |
| 513 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 514 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 515 | |
| 516 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 517 | FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 518 | |
| 519 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 520 | FPDF_WIDESTRING encode = |
| 521 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 522 | |
| 523 | return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); |
| 524 | } |
| 525 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 526 | CFX_WideString CPDFSDK_FormFillEnvironment::GetLanguage() { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 527 | if (!m_pInfo || !m_pInfo->FFI_GetLanguage) |
| 528 | return L""; |
| 529 | |
| 530 | int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); |
| 531 | if (nRequiredLen <= 0) |
| 532 | return L""; |
| 533 | |
| 534 | char* pbuff = new char[nRequiredLen]; |
| 535 | memset(pbuff, 0, nRequiredLen); |
| 536 | int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); |
| 537 | if (nActualLen <= 0 || nActualLen > nRequiredLen) { |
| 538 | delete[] pbuff; |
| 539 | return L""; |
| 540 | } |
| 541 | CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); |
| 542 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 543 | (FPDF_WIDESTRING)bsRet.GetBuffer(bsRet.GetLength()), |
| 544 | bsRet.GetLength() / sizeof(FPDF_WIDESTRING)); |
| 545 | delete[] pbuff; |
| 546 | return wsRet; |
| 547 | } |
| 548 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame^] | 549 | void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount, |
| 550 | uint32_t dwEventType) const { |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 551 | if (m_pInfo && m_pInfo->FFI_PageEvent) |
| 552 | m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); |
| 553 | } |
| 554 | #endif // PDF_ENABLE_XFA |