Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp

Issue 2549573003: Make concrete stream classes private to .cpp, part 4. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | fpdfsdk/fsdk_define.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fpdfxfa/cpdfxfa_docenvironment.h" 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 bs = filepath.UTF16LE_Encode(); 430 bs = filepath.UTF16LE_Encode();
431 } 431 }
432 int len = bs.GetLength(); 432 int len = bs.GetLength();
433 FPDF_FILEHANDLER* pFileHandler = 433 FPDF_FILEHANDLER* pFileHandler =
434 pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, 434 pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
435 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); 435 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb");
436 bs.ReleaseBuffer(len); 436 bs.ReleaseBuffer(len);
437 if (!pFileHandler) 437 if (!pFileHandler)
438 return; 438 return;
439 439
440 CFPDF_FileStream fileWrite(pFileHandler); 440 std::unique_ptr<IFX_SeekableStream, ReleaseDeleter<IFX_SeekableStream>>
441 fileWrite(MakeSeekableStream(pFileHandler));
441 CFX_ByteString content; 442 CFX_ByteString content;
442 if (fileType == FXFA_SAVEAS_XML) { 443 if (fileType == FXFA_SAVEAS_XML) {
443 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; 444 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
444 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), 445 fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(),
445 content.GetLength()); 446 content.GetLength());
446 m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, 447 m_pContext->GetXFADocView()->GetDoc()->SavePackage(
447 &fileWrite, nullptr); 448 XFA_HASHCODE_Data, fileWrite.get(), nullptr);
448 } else if (fileType == FXFA_SAVEAS_XDP) { 449 } else if (fileType == FXFA_SAVEAS_XDP) {
449 if (!m_pContext->GetPDFDoc()) 450 if (!m_pContext->GetPDFDoc())
450 return; 451 return;
451 452
452 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); 453 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
453 if (!pRoot) 454 if (!pRoot)
454 return; 455 return;
455 456
456 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); 457 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
457 if (!pAcroForm) 458 if (!pAcroForm)
458 return; 459 return;
459 460
460 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); 461 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA"));
461 if (!pArray) 462 if (!pArray)
462 return; 463 return;
463 464
464 int size = pArray->GetCount(); 465 int size = pArray->GetCount();
465 for (int i = 1; i < size; i += 2) { 466 for (int i = 1; i < size; i += 2) {
466 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); 467 CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
467 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); 468 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
468 if (!pPrePDFObj->IsString()) 469 if (!pPrePDFObj->IsString())
469 continue; 470 continue;
470 if (!pPDFObj->IsReference()) 471 if (!pPDFObj->IsReference())
471 continue; 472 continue;
472 473
473 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); 474 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect());
474 if (!pStream) 475 if (!pStream)
475 continue; 476 continue;
476 if (pPrePDFObj->GetString() == "form") { 477 if (pPrePDFObj->GetString() == "form") {
477 m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Form, 478 m_pContext->GetXFADocView()->GetDoc()->SavePackage(
478 &fileWrite, nullptr); 479 XFA_HASHCODE_Form, fileWrite.get(), nullptr);
479 continue; 480 continue;
480 } 481 }
481 if (pPrePDFObj->GetString() == "datasets") { 482 if (pPrePDFObj->GetString() == "datasets") {
482 m_pContext->GetXFADocView()->GetDoc()->SavePackage( 483 m_pContext->GetXFADocView()->GetDoc()->SavePackage(
483 XFA_HASHCODE_Datasets, &fileWrite, nullptr); 484 XFA_HASHCODE_Datasets, fileWrite.get(), nullptr);
484 continue; 485 continue;
485 } 486 }
486 if (i == size - 1) { 487 if (i == size - 1) {
487 CFX_WideString wPath = CFX_WideString::FromUTF16LE( 488 CFX_WideString wPath = CFX_WideString::FromUTF16LE(
488 reinterpret_cast<const unsigned short*>(bs.c_str()), 489 reinterpret_cast<const unsigned short*>(bs.c_str()),
489 bs.GetLength() / sizeof(unsigned short)); 490 bs.GetLength() / sizeof(unsigned short));
490 CFX_ByteString bPath = wPath.UTF8Encode(); 491 CFX_ByteString bPath = wPath.UTF8Encode();
491 const char* szFormat = 492 const char* szFormat =
492 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; 493 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
493 content.Format(szFormat, bPath.c_str()); 494 content.Format(szFormat, bPath.c_str());
494 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), 495 fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(),
495 content.GetLength()); 496 content.GetLength());
496 } 497 }
497 std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); 498 std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc);
498 pAcc->LoadAllData(pStream); 499 pAcc->LoadAllData(pStream);
499 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), 500 fileWrite->WriteBlock(pAcc->GetData(), fileWrite->GetSize(),
500 pAcc->GetSize()); 501 pAcc->GetSize());
501 } 502 }
502 } 503 }
503 if (!fileWrite.Flush()) { 504 fileWrite->Flush();
504 // Ignoring flush error.
505 }
506 } 505 }
507 506
508 void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, 507 void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc,
509 const CFX_WideString& bsURL) { 508 const CFX_WideString& bsURL) {
510 if (hDoc != m_pContext->GetXFADoc()) 509 if (hDoc != m_pContext->GetXFADoc())
511 return; 510 return;
512 511
513 if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA) 512 if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA)
514 return; 513 return;
515 514
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 return nullptr; 707 return nullptr;
709 708
710 CFX_ByteString bs = wsLink.UTF16LE_Encode(); 709 CFX_ByteString bs = wsLink.UTF16LE_Encode();
711 int len = bs.GetLength(); 710 int len = bs.GetLength();
712 FPDF_FILEHANDLER* pFileHandler = 711 FPDF_FILEHANDLER* pFileHandler =
713 pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); 712 pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb");
714 bs.ReleaseBuffer(len); 713 bs.ReleaseBuffer(len);
715 if (!pFileHandler) 714 if (!pFileHandler)
716 return nullptr; 715 return nullptr;
717 716
718 return new CFPDF_FileStream(pFileHandler); 717 return MakeSeekableStream(pFileHandler);
719 } 718 }
720 719
721 bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, 720 bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
722 int fileType, 721 int fileType,
723 FPDF_DWORD encodeType, 722 FPDF_DWORD encodeType,
724 FPDF_DWORD flag) { 723 FPDF_DWORD flag) {
725 if (!m_pContext->GetXFADocView()) 724 if (!m_pContext->GetXFADocView())
726 return false; 725 return false;
727 726
728 CFX_ByteString content; 727 CFX_ByteString content;
729 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); 728 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
730 if (!pFormFillEnv) 729 if (!pFormFillEnv)
731 return false; 730 return false;
732 731
733 CFPDF_FileStream fileStream(pFileHandler); 732 std::unique_ptr<IFX_SeekableStream, ReleaseDeleter<IFX_SeekableStream>>
733 fileStream(MakeSeekableStream(pFileHandler));
734
734 if (fileType == FXFA_SAVEAS_XML) { 735 if (fileType == FXFA_SAVEAS_XML) {
735 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; 736 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
736 fileStream.WriteBlock(kContent, 0, strlen(kContent)); 737 fileStream->WriteBlock(kContent, 0, strlen(kContent));
737 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, &fileStream, 738 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, fileStream.get(),
738 nullptr); 739 nullptr);
739 return true; 740 return true;
740 } 741 }
741 742
742 if (fileType != FXFA_SAVEAS_XDP) 743 if (fileType != FXFA_SAVEAS_XDP)
743 return true; 744 return true;
744 745
745 if (!flag) { 746 if (!flag) {
746 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | 747 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
747 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; 748 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
748 } 749 }
749 if (!m_pContext->GetPDFDoc()) { 750 if (!m_pContext->GetPDFDoc()) {
750 fileStream.Flush(); 751 fileStream->Flush();
751 return false; 752 return false;
752 } 753 }
753 754
754 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); 755 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
755 if (!pRoot) { 756 if (!pRoot) {
756 fileStream.Flush(); 757 fileStream->Flush();
757 return false; 758 return false;
758 } 759 }
759 760
760 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); 761 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
761 if (!pAcroForm) { 762 if (!pAcroForm) {
762 fileStream.Flush(); 763 fileStream->Flush();
763 return false; 764 return false;
764 } 765 }
765 766
766 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); 767 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA"));
767 if (!pArray) { 768 if (!pArray) {
768 fileStream.Flush(); 769 fileStream->Flush();
769 return false; 770 return false;
770 } 771 }
771 772
772 int size = pArray->GetCount(); 773 int size = pArray->GetCount();
773 for (int i = 1; i < size; i += 2) { 774 for (int i = 1; i < size; i += 2) {
774 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); 775 CPDF_Object* pPDFObj = pArray->GetObjectAt(i);
775 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); 776 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1);
776 if (!pPrePDFObj->IsString()) 777 if (!pPrePDFObj->IsString())
777 continue; 778 continue;
778 if (!pPDFObj->IsReference()) 779 if (!pPDFObj->IsReference())
(...skipping 10 matching lines...) Expand all
789 continue; 790 continue;
790 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) 791 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS))
791 continue; 792 continue;
792 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) 793 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA))
793 continue; 794 continue;
794 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) 795 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF))
795 continue; 796 continue;
796 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) 797 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM))
797 continue; 798 continue;
798 if (pPrePDFObj->GetString() == "form") { 799 if (pPrePDFObj->GetString() == "form") {
799 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, &fileStream, 800 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, fileStream.get(),
800 nullptr); 801 nullptr);
801 } else if (pPrePDFObj->GetString() == "datasets") { 802 } else if (pPrePDFObj->GetString() == "datasets") {
802 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, &fileStream, 803 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets,
803 nullptr); 804 fileStream.get(), nullptr);
804 } else { 805 } else {
805 // PDF,creator. 806 // PDF,creator.
806 } 807 }
807 } 808 }
808 return true; 809 return true;
809 } 810 }
810 811
811 void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent, 812 void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent,
812 FPDF_DWORD& flag) { 813 FPDF_DWORD& flag) {
813 if (csSrcContent.Find(L" config ", 0) != -1) 814 if (csSrcContent.Find(L" config ", 0) != -1)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 !m_pContext->GetFormFillEnv()->GetJSRuntime()) { 1020 !m_pContext->GetFormFillEnv()->GetJSRuntime()) {
1020 return false; 1021 return false;
1021 } 1022 }
1022 1023
1023 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); 1024 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
1024 if (!m_pJSContext) 1025 if (!m_pJSContext)
1025 m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext(); 1026 m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext();
1026 1027
1027 return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); 1028 return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue);
1028 } 1029 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | fpdfsdk/fsdk_define.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698