Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../public/fpdf_ext.h" | 7 #include "../../public/fpdf_ext.h" |
| 8 #include "../../third_party/base/nonstd_unique_ptr.h" | 8 #include "../../third_party/base/nonstd_unique_ptr.h" |
| 9 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
| 10 #include "../include/fsdk_mgr.h" | 10 #include "../include/fsdk_mgr.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return m_pEnv->FFI_GetLocalTime(); | 212 return m_pEnv->FFI_GetLocalTime(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 | 215 |
| 216 CJS_RuntimeFactory* GetJSRuntimeFactory() | 216 CJS_RuntimeFactory* GetJSRuntimeFactory() |
| 217 { | 217 { |
| 218 static CJS_RuntimeFactory s_JSRuntimeFactory; | 218 static CJS_RuntimeFactory s_JSRuntimeFactory; |
| 219 return &s_JSRuntimeFactory; | 219 return &s_JSRuntimeFactory; |
| 220 } | 220 } |
| 221 | 221 |
| 222 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc) : | 222 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo) : |
| 223 m_pAnnotHandlerMgr(NULL), | 223 m_pAnnotHandlerMgr(NULL), |
| 224 m_pActionHandler(NULL), | 224 m_pActionHandler(NULL), |
| 225 m_pJSRuntime(NULL), | 225 m_pJSRuntime(NULL), |
| 226 » m_pInfo(NULL), | 226 » m_pInfo(pFFinfo), |
| 227 m_pSDKDoc(NULL), | 227 m_pSDKDoc(NULL), |
| 228 m_pPDFDoc(pDoc), | 228 m_pPDFDoc(pDoc), |
| 229 m_pIFormFiller(NULL) | 229 m_pIFormFiller(NULL) |
| 230 { | 230 { |
| 231 | |
| 232 m_pSysHandler = NULL; | |
| 233 m_pSysHandler = new CFX_SystemHandler(this); | 231 m_pSysHandler = new CFX_SystemHandler(this); |
| 234 | |
| 235 | |
| 236 m_pJSRuntimeFactory = NULL; | |
| 237 m_pJSRuntimeFactory = GetJSRuntimeFactory(); | 232 m_pJSRuntimeFactory = GetJSRuntimeFactory(); |
| 238 m_pJSRuntimeFactory->AddRef(); | 233 m_pJSRuntimeFactory->AddRef(); |
| 239 } | 234 } |
| 240 | 235 |
| 241 CPDFDoc_Environment::~CPDFDoc_Environment() | 236 CPDFDoc_Environment::~CPDFDoc_Environment() |
| 242 { | 237 { |
| 243 delete m_pIFormFiller; | 238 delete m_pIFormFiller; |
| 244 m_pIFormFiller = NULL; | 239 m_pIFormFiller = NULL; |
| 245 if (m_pJSRuntime && m_pJSRuntimeFactory) | 240 if (m_pJSRuntime && m_pJSRuntimeFactory) |
| 246 m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime); | 241 m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime); |
| 247 m_pJSRuntimeFactory->Release(); | 242 m_pJSRuntimeFactory->Release(); |
| 248 | 243 |
| 249 delete m_pSysHandler; | 244 delete m_pSysHandler; |
| 250 m_pSysHandler = NULL; | 245 m_pSysHandler = NULL; |
| 251 | 246 |
| 252 delete m_pAnnotHandlerMgr; | 247 delete m_pAnnotHandlerMgr; |
| 253 m_pAnnotHandlerMgr = NULL; | 248 m_pAnnotHandlerMgr = NULL; |
| 254 delete m_pActionHandler; | 249 delete m_pActionHandler; |
| 255 m_pActionHandler = NULL; | 250 m_pActionHandler = NULL; |
| 256 } | 251 } |
| 257 | 252 |
| 253 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon) | |
| 254 { | |
| 255 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) | |
| 256 { | |
| 257 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); | |
| 258 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); | |
| 259 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength( )); | |
| 260 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetL ength()); | |
| 261 int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg , pTitle, Type, Icon); | |
| 262 bsMsg.ReleaseBuffer(); | |
| 263 bsTitle.ReleaseBuffer(); | |
| 264 return ret; | |
| 265 } | |
| 266 return -1; | |
| 267 } | |
| 268 | |
| 269 int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR * Title, const FX_WCHAR* Default, | |
| 270 const FX_WCHAR* cLabel, FPDF_BOOL bPassw ord, void* response, int length) | |
| 271 { | |
| 272 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_respons e) | |
| 273 { | |
| 274 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); | |
| 275 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); | |
| 276 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); | |
| 277 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); | |
| 278 FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQues tion.GetLength()); | |
| 279 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetL ength()); | |
| 280 FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefaul t.GetLength()); | |
| 281 FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetL ength()); | |
| 282 int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, p Question, pTitle, | |
| 283 pDefault, pLabel, bPasswo rd, response, length); | |
| 284 bsQuestion.ReleaseBuffer(); | |
| 285 bsTitle.ReleaseBuffer(); | |
| 286 bsDefault.ReleaseBuffer(); | |
| 287 bsLabel.ReleaseBuffer(); | |
| 288 return ret; | |
| 289 } | |
| 290 return -1; | |
| 291 } | |
| 292 | |
| 258 CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() | 293 CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() |
| 259 { | 294 { |
| 260 if (!m_pInfo || | 295 if (!m_pInfo || |
| 261 !m_pInfo->m_pJsPlatform || | 296 !m_pInfo->m_pJsPlatform || |
| 262 !m_pInfo->m_pJsPlatform->Field_browse) { | 297 !m_pInfo->m_pJsPlatform->Field_browse) { |
| 263 return L""; | 298 return L""; |
| 264 } | 299 } |
| 265 | 300 |
| 266 const int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse( | 301 const int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 267 m_pInfo->m_pJsPlatform, nullptr, 0); | 302 m_pInfo->m_pJsPlatform, nullptr, 0); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 298 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( | 333 const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 299 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); | 334 m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 300 if (nActualLen <= 0 || nActualLen > nRequiredLen) | 335 if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 301 return L""; | 336 return L""; |
| 302 | 337 |
| 303 CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); | 338 CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 304 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); | 339 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 305 return wsRet; | 340 return wsRet; |
| 306 } | 341 } |
| 307 | 342 |
| 343 void CPDFDoc_Environment::JS_docSubmitForm(void* formData, int length, const FX_ WCHAR* URL) | |
| 344 { | |
| 345 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitF orm) | |
| 346 { | |
| 347 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); | |
| 348 FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer( bsDestination.GetLength()); | |
| 349 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination); | |
| 350 bsDestination.ReleaseBuffer(); | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 void CPDFDoc_Environment::JS_docmailForm(void* mailData, int length, FPDF_BOOL b UI, | |
| 355 const FX_WCHAR* To, const FX_WCHAR* Sub ject, | |
| 356 const FX_WCHAR* CC, const FX_WCHAR* BCC , | |
| 357 const FX_WCHAR* Msg) | |
| 358 { | |
| 359 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) | |
| 360 { | |
| 361 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); | |
| 362 CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); | |
| 363 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); | |
| 364 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); | |
| 365 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); | |
| 366 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); | |
| 367 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); | |
| 368 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength( )); | |
| 369 FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubjec t.GetLength()); | |
| 370 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength( )); | |
| 371 m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, lengt h, bUI, pTo, pSubject, | |
| 372 pCC, pBcc, pMsg); | |
| 373 bsTo.ReleaseBuffer(); | |
| 374 bsCC.ReleaseBuffer(); | |
| 375 bsBcc.ReleaseBuffer(); | |
| 376 bsSubject.ReleaseBuffer(); | |
| 377 bsMsg.ReleaseBuffer(); | |
| 378 } | |
| 379 } | |
| 380 | |
| 308 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() | 381 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() |
| 309 { | 382 { |
| 310 » if(!IsJSInitiated()) | 383 » if (!IsJSInitiated()) |
|
Lei Zhang
2015/07/16 17:05:06
kill tabs here and below
Tom Sepez
2015/07/16 18:01:28
Untabified file.
| |
| 311 return NULL; | 384 return NULL; |
| 312 » assert(m_pJSRuntimeFactory); | 385 » if (!m_pJSRuntime) |
| 313 » if(!m_pJSRuntime) | |
| 314 m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this); | 386 m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this); |
| 315 return m_pJSRuntime; | 387 return m_pJSRuntime; |
| 316 } | 388 } |
| 317 | 389 |
| 318 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() | 390 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() |
| 319 { | 391 { |
| 320 » if(!m_pAnnotHandlerMgr) | 392 » if (!m_pAnnotHandlerMgr) |
| 321 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); | 393 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); |
| 322 return m_pAnnotHandlerMgr; | 394 return m_pAnnotHandlerMgr; |
| 323 } | 395 } |
| 324 | 396 |
| 325 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() | 397 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() |
| 326 { | 398 { |
| 327 » if(!m_pActionHandler) | 399 » if (!m_pActionHandler) |
| 328 m_pActionHandler = new CPDFSDK_ActionHandler(this); | 400 m_pActionHandler = new CPDFSDK_ActionHandler(this); |
| 329 return m_pActionHandler; | 401 return m_pActionHandler; |
| 330 } | 402 } |
| 331 | 403 |
| 332 int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo) | |
| 333 { | |
| 334 m_pInfo = pFFinfo; | |
| 335 return TRUE; | |
| 336 } | |
| 337 | |
| 338 CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc() | |
| 339 { | |
| 340 return m_pSDKDoc; | |
| 341 } | |
| 342 | |
| 343 CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() | 404 CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() |
| 344 { | 405 { |
| 345 » if(!m_pIFormFiller) | 406 » if (!m_pIFormFiller) |
| 346 m_pIFormFiller = new CFFL_IFormFiller(this); | 407 m_pIFormFiller = new CFFL_IFormFiller(this); |
| 347 return m_pIFormFiller; | 408 return m_pIFormFiller; |
| 348 } | 409 } |
| 349 | 410 |
| 350 FX_BOOL»CPDFDoc_Environment::IsJSInitiated() | 411 CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv ) : |
| 412 m_pDoc(pDoc), | |
| 413 m_pInterForm(NULL), | |
|
Lei Zhang
2015/07/16 17:05:06
nullptr
| |
| 414 m_pEnv(pEnv), | |
| 415 m_pOccontent(NULL), | |
| 416 m_bChangeMask(FALSE), | |
| 417 » m_pFocusAnnot(NULL) | |
| 351 { | 418 { |
| 352 if(m_pInfo) | |
| 353 { | |
| 354 if(m_pInfo->m_pJsPlatform) | |
| 355 return TRUE; | |
| 356 else | |
| 357 return FALSE; | |
| 358 } | |
| 359 return FALSE; | |
| 360 } | |
| 361 | |
| 362 CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv ):m_pDoc(pDoc), | |
| 363 m_pInterForm(NULL),m_pEnv(pEnv), m_pOccontent(NULL),m_bChangeMask(FALSE) | |
| 364 { | |
| 365 m_pFocusAnnot = NULL; | |
| 366 } | 419 } |
| 367 | 420 |
| 368 CPDFSDK_Document::~CPDFSDK_Document() | 421 CPDFSDK_Document::~CPDFSDK_Document() |
| 369 { | 422 { |
| 370 for (auto& it : m_pageMap) | 423 for (auto& it : m_pageMap) |
| 371 delete it.second; | 424 delete it.second; |
| 372 m_pageMap.clear(); | 425 m_pageMap.clear(); |
| 373 | 426 |
| 374 delete m_pInterForm; | 427 delete m_pInterForm; |
| 375 m_pInterForm = nullptr; | 428 m_pInterForm = nullptr; |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 | 1095 |
| 1043 for(int i=0; i<m_fxAnnotArray.GetSize(); i++) | 1096 for(int i=0; i<m_fxAnnotArray.GetSize(); i++) |
| 1044 { | 1097 { |
| 1045 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); | 1098 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 1046 if(pAnnot == pFocusAnnot) | 1099 if(pAnnot == pFocusAnnot) |
| 1047 return pAnnot; | 1100 return pAnnot; |
| 1048 } | 1101 } |
| 1049 return NULL; | 1102 return NULL; |
| 1050 } | 1103 } |
| 1051 | 1104 |
| OLD | NEW |