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