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

Side by Side Diff: core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp

Issue 2358243002: Use unique_ptr<CPDF_Object, ReleaseDeleter<>> in more places (Closed)
Patch Set: Created 4 years, 2 months 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 | « no previous file | core/fpdfapi/fpdf_edit/include/cpdf_creator.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 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 "core/fpdfapi/fpdf_edit/editint.h" 7 #include "core/fpdfapi/fpdf_edit/editint.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 offset += len; 807 offset += len;
808 if (pFile->AppendString("/Length ") < 0) 808 if (pFile->AppendString("/Length ") < 0)
809 return FALSE; 809 return FALSE;
810 810
811 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) 811 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0)
812 return FALSE; 812 return FALSE;
813 813
814 offset += len + 8; 814 offset += len + 8;
815 if (bEOF) { 815 if (bEOF) {
816 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, 816 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile,
817 pCreator->m_pIDArray)) < 0) { 817 pCreator->m_pIDArray.get())) < 0) {
818 return FALSE; 818 return FALSE;
819 } 819 }
820 offset += len; 820 offset += len;
821 if (pCreator->m_pEncryptDict) { 821 if (pCreator->m_pEncryptDict) {
822 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); 822 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum();
823 if (dwEncryptObjNum == 0) { 823 if (dwEncryptObjNum == 0) {
824 dwEncryptObjNum = pCreator->m_dwEncryptObjNum; 824 dwEncryptObjNum = pCreator->m_dwEncryptObjNum;
825 } 825 }
826 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, 826 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict,
827 dwEncryptObjNum, pFile)) < 0) { 827 dwEncryptObjNum, pFile)) < 0) {
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { 1803 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) {
1804 return -1; 1804 return -1;
1805 } 1805 }
1806 } 1806 }
1807 } 1807 }
1808 if (m_pIDArray) { 1808 if (m_pIDArray) {
1809 if (m_File.AppendString(("/ID")) < 0) { 1809 if (m_File.AppendString(("/ID")) < 0) {
1810 return -1; 1810 return -1;
1811 } 1811 }
1812 FX_FILESIZE offset = 0; 1812 FX_FILESIZE offset = 0;
1813 if (PDF_CreatorAppendObject(m_pIDArray, &m_File, offset) < 0) { 1813 if (PDF_CreatorAppendObject(m_pIDArray.get(), &m_File, offset) < 0) {
1814 return -1; 1814 return -1;
1815 } 1815 }
1816 } 1816 }
1817 if (!bXRefStream) { 1817 if (!bXRefStream) {
1818 if (m_File.AppendString(">>") < 0) { 1818 if (m_File.AppendString(">>") < 0) {
1819 return -1; 1819 return -1;
1820 } 1820 }
1821 } else { 1821 } else {
1822 if (m_File.AppendString("/W[0 4 1]/Index[") < 0) { 1822 if (m_File.AppendString("/W[0 4 1]/Index[") < 0) {
1823 return -1; 1823 return -1;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 return -1; 1897 return -1;
1898 } 1898 }
1899 m_File.Flush(); 1899 m_File.Flush();
1900 return m_iStage = 100; 1900 return m_iStage = 100;
1901 } 1901 }
1902 1902
1903 void CPDF_Creator::Clear() { 1903 void CPDF_Creator::Clear() {
1904 m_pXRefStream.reset(); 1904 m_pXRefStream.reset();
1905 m_File.Clear(); 1905 m_File.Clear();
1906 m_NewObjNumArray.RemoveAll(); 1906 m_NewObjNumArray.RemoveAll();
1907 if (m_pIDArray) { 1907 m_pIDArray.reset();
1908 m_pIDArray->Release();
1909 m_pIDArray = nullptr;
1910 }
1911 } 1908 }
1912 1909
1913 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { 1910 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) {
1914 m_File.AttachFile(pFile); 1911 m_File.AttachFile(pFile);
1915 return Create(flags); 1912 return Create(flags);
1916 } 1913 }
1917 1914
1918 bool CPDF_Creator::Create(uint32_t flags) { 1915 bool CPDF_Creator::Create(uint32_t flags) {
1919 m_dwFlags = flags; 1916 m_dwFlags = flags;
1920 m_iStage = 0; 1917 m_iStage = 0;
1921 m_Offset = 0; 1918 m_Offset = 0;
1922 m_dwLastObjNum = m_pDocument->GetLastObjNum(); 1919 m_dwLastObjNum = m_pDocument->GetLastObjNum();
1923 m_ObjectOffset.Clear(); 1920 m_ObjectOffset.Clear();
1924 m_NewObjNumArray.RemoveAll(); 1921 m_NewObjNumArray.RemoveAll();
1925 InitID(); 1922 InitID();
1926 if (flags & FPDFCREATE_PROGRESSIVE) 1923 if (flags & FPDFCREATE_PROGRESSIVE)
1927 return true; 1924 return true;
1928 return Continue(nullptr) > -1; 1925 return Continue(nullptr) > -1;
1929 } 1926 }
1930 1927
1931 void CPDF_Creator::InitID(FX_BOOL bDefault) { 1928 void CPDF_Creator::InitID(FX_BOOL bDefault) {
1932 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; 1929 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr;
1933 FX_BOOL bNewId = !m_pIDArray; 1930 FX_BOOL bNewId = !m_pIDArray;
1934 if (!m_pIDArray) { 1931 if (bNewId) {
1935 m_pIDArray = new CPDF_Array; 1932 m_pIDArray.reset(new CPDF_Array);
1936 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; 1933 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr;
1937 if (pID1) { 1934 if (pID1) {
1938 m_pIDArray->Add(pID1->Clone()); 1935 m_pIDArray->Add(pID1->Clone());
1939 } else { 1936 } else {
1940 std::vector<uint8_t> buffer = 1937 std::vector<uint8_t> buffer =
1941 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); 1938 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum);
1942 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); 1939 CFX_ByteString bsBuffer(buffer.data(), buffer.size());
1943 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); 1940 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE));
1944 } 1941 }
1945 } 1942 }
(...skipping 12 matching lines...) Expand all
1958 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); 1955 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE));
1959 return; 1956 return;
1960 } 1957 }
1961 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); 1958 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone());
1962 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { 1959 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) {
1963 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { 1960 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") {
1964 CFX_ByteString user_pass = m_pParser->GetPassword(); 1961 CFX_ByteString user_pass = m_pParser->GetPassword();
1965 uint32_t flag = PDF_ENCRYPT_CONTENT; 1962 uint32_t flag = PDF_ENCRYPT_CONTENT;
1966 1963
1967 CPDF_SecurityHandler handler; 1964 CPDF_SecurityHandler handler;
1968 handler.OnCreate(m_pEncryptDict, m_pIDArray, user_pass.raw_str(), 1965 handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(),
1969 user_pass.GetLength(), flag); 1966 user_pass.GetLength(), flag);
1970 if (m_bLocalCryptoHandler) 1967 if (m_bLocalCryptoHandler)
1971 delete m_pCryptoHandler; 1968 delete m_pCryptoHandler;
1972 m_pCryptoHandler = new CPDF_CryptoHandler; 1969 m_pCryptoHandler = new CPDF_CryptoHandler;
1973 m_pCryptoHandler->Init(m_pEncryptDict, &handler); 1970 m_pCryptoHandler->Init(m_pEncryptDict, &handler);
1974 m_bLocalCryptoHandler = TRUE; 1971 m_bLocalCryptoHandler = TRUE;
1975 m_bSecurityChanged = TRUE; 1972 m_bSecurityChanged = TRUE;
1976 } 1973 }
1977 } 1974 }
1978 } 1975 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 m_pCryptoHandler = nullptr; 2013 m_pCryptoHandler = nullptr;
2017 } 2014 }
2018 void CPDF_Creator::ResetStandardSecurity() { 2015 void CPDF_Creator::ResetStandardSecurity() {
2019 if (!m_bLocalCryptoHandler) 2016 if (!m_bLocalCryptoHandler)
2020 return; 2017 return;
2021 2018
2022 delete m_pCryptoHandler; 2019 delete m_pCryptoHandler;
2023 m_pCryptoHandler = nullptr; 2020 m_pCryptoHandler = nullptr;
2024 m_bLocalCryptoHandler = FALSE; 2021 m_bLocalCryptoHandler = FALSE;
2025 } 2022 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_edit/include/cpdf_creator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698