Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "fpdfsdk/cpdfsdk_interform.h" | 7 #include "fpdfsdk/cpdfsdk_interform.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 return true; | 456 return true; |
| 457 } | 457 } |
| 458 | 458 |
| 459 bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, | 459 bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
| 460 CFX_WideString csTxtFile) { | 460 CFX_WideString csTxtFile) { |
| 461 return true; | 461 return true; |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, | 464 bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
| 465 FX_STRSIZE& nBufSize) { | 465 FX_STRSIZE& nBufSize) { |
| 466 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); | 466 std::unique_ptr<CFDF_Document> pFDF = |
|
Tom Sepez
2016/11/28 23:21:55
Note: I can't figure out why this didn't leak and
Wei Li
2016/11/29 01:25:34
This path is not tested. :(
| |
| 467 CFDF_Document::ParseMemory(pBuf, nBufSize); | |
| 467 if (!pFDF) | 468 if (!pFDF) |
| 468 return true; | 469 return true; |
| 469 | 470 |
| 470 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); | 471 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); |
| 471 if (!pMainDict) | 472 if (!pMainDict) |
| 472 return false; | 473 return false; |
| 473 | 474 |
| 474 CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); | 475 CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); |
| 475 if (!pFields) | 476 if (!pFields) |
| 476 return false; | 477 return false; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 499 nBufSize = fdfEncodedData.GetLength(); | 500 nBufSize = fdfEncodedData.GetLength(); |
| 500 pBuf = FX_Alloc(uint8_t, nBufSize); | 501 pBuf = FX_Alloc(uint8_t, nBufSize); |
| 501 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); | 502 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
| 502 return true; | 503 return true; |
| 503 } | 504 } |
| 504 | 505 |
| 505 bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( | 506 bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| 506 const std::vector<CPDF_FormField*>& fields, | 507 const std::vector<CPDF_FormField*>& fields, |
| 507 bool bIncludeOrExclude, | 508 bool bIncludeOrExclude, |
| 508 CFX_ByteTextBuf& textBuf) { | 509 CFX_ByteTextBuf& textBuf) { |
| 509 std::unique_ptr<CFDF_Document> pFDF( | 510 std::unique_ptr<CFDF_Document> pFDF = |
| 510 m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), | 511 m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), |
| 511 fields, bIncludeOrExclude, false)); | 512 fields, bIncludeOrExclude, false); |
| 512 return pFDF ? pFDF->WriteBuf(textBuf) : false; | 513 return pFDF ? pFDF->WriteBuf(textBuf) : false; |
| 513 } | 514 } |
| 514 | 515 |
| 515 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( | 516 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 516 const CFX_WideString& sFileExt) { | 517 const CFX_WideString& sFileExt) { |
| 517 return L""; | 518 return L""; |
| 518 } | 519 } |
| 519 | 520 |
| 520 bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, | 521 bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
| 521 bool bUrlEncoded) { | 522 bool bUrlEncoded) { |
| 522 if (sDestination.IsEmpty()) | 523 if (sDestination.IsEmpty()) |
| 523 return false; | 524 return false; |
| 524 | 525 |
| 525 if (!m_pFormFillEnv || !m_pInterForm) | 526 if (!m_pFormFillEnv || !m_pInterForm) |
| 526 return false; | 527 return false; |
| 527 | 528 |
| 528 CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); | 529 std::unique_ptr<CFDF_Document> pFDFDoc = m_pInterForm->ExportToFDF( |
| 529 CFDF_Document* pFDFDoc = | 530 m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); |
| 530 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); | |
| 531 if (!pFDFDoc) | 531 if (!pFDFDoc) |
| 532 return false; | 532 return false; |
| 533 | 533 |
| 534 CFX_ByteTextBuf FdfBuffer; | 534 CFX_ByteTextBuf FdfBuffer; |
| 535 bool bRet = pFDFDoc->WriteBuf(FdfBuffer); | 535 if (!pFDFDoc->WriteBuf(FdfBuffer)) |
| 536 delete pFDFDoc; | |
| 537 if (!bRet) | |
| 538 return false; | 536 return false; |
| 539 | 537 |
| 540 uint8_t* pBuffer = FdfBuffer.GetBuffer(); | 538 uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
| 541 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); | 539 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
| 542 | |
| 543 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) | 540 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
| 544 return false; | 541 return false; |
| 545 | 542 |
| 546 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); | 543 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
| 547 | |
| 548 if (bUrlEncoded) | 544 if (bUrlEncoded) |
| 549 FX_Free(pBuffer); | 545 FX_Free(pBuffer); |
| 550 | 546 |
| 551 return true; | 547 return true; |
| 552 } | 548 } |
| 553 | 549 |
| 554 bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { | 550 bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
| 555 CFDF_Document* pFDF = m_pInterForm->ExportToFDF( | 551 std::unique_ptr<CFDF_Document> pFDF = m_pInterForm->ExportToFDF( |
| 556 m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); | 552 m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); |
| 557 if (!pFDF) | 553 return pFDF && pFDF->WriteBuf(textBuf); |
| 558 return false; | |
| 559 | |
| 560 bool bRet = pFDF->WriteBuf(textBuf); | |
| 561 delete pFDF; | |
| 562 | |
| 563 return bRet; | |
| 564 } | 554 } |
| 565 | 555 |
| 566 bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { | 556 bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
| 567 ASSERT(action.GetDict()); | 557 ASSERT(action.GetDict()); |
| 568 | 558 |
| 569 CPDF_Dictionary* pActionDict = action.GetDict(); | 559 CPDF_Dictionary* pActionDict = action.GetDict(); |
| 570 if (!pActionDict->KeyExist("Fields")) | 560 if (!pActionDict->KeyExist("Fields")) |
| 571 return m_pInterForm->ResetForm(true); | 561 return m_pInterForm->ResetForm(true); |
| 572 | 562 |
| 573 CPDF_ActionFields af(&action); | 563 CPDF_ActionFields af(&action); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 } | 693 } |
| 704 } | 694 } |
| 705 | 695 |
| 706 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { | 696 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
| 707 if (nFieldType < 0 || nFieldType > kNumFieldTypes) | 697 if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
| 708 return FXSYS_RGB(255, 255, 255); | 698 return FXSYS_RGB(255, 255, 255); |
| 709 if (nFieldType == 0) | 699 if (nFieldType == 0) |
| 710 return m_aHighlightColor[0]; | 700 return m_aHighlightColor[0]; |
| 711 return m_aHighlightColor[nFieldType - 1]; | 701 return m_aHighlightColor[nFieldType - 1]; |
| 712 } | 702 } |
| OLD | NEW |