summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-10-14 16:59:10 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-14 16:59:10 -0700
commit3ba098595ae56b64eacc0c25ab76b89a4d78d920 (patch)
tree5c4db47295ea64cdf236c32ef7d5af5b8e7af232 /core/fpdfapi/edit
parent1d023881cd53485303c0fcc0b5878e700dc470fd (diff)
downloadpdfium-3ba098595ae56b64eacc0c25ab76b89a4d78d920.tar.xz
Update CPDF_IndirectObjectHolder APIs for unique objects.
Doing so highlights a few places where ownership is dubious. Add convenience functions to return an unowned reference to a newly-created indirect object. Review-Url: https://codereview.chromium.org/2419173002
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp22
-rw-r--r--core/fpdfapi/edit/fpdf_edit_create.cpp8
2 files changed, 13 insertions, 17 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index ad1ffaf687..654b69ec4a 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -52,10 +52,9 @@ void CPDF_PageContentGenerator::GenerateContent() {
if (pContent)
pPageDict->RemoveFor("Contents");
- CPDF_Stream* pStream = new CPDF_Stream;
+ CPDF_Stream* pStream = m_pDocument->AddIndirectStream();
pStream->SetData(buf.GetBuffer(), buf.GetLength());
- pPageDict->SetReferenceFor("Contents", m_pDocument,
- m_pDocument->AddIndirectObject(pStream));
+ pPageDict->SetReferenceFor("Contents", m_pDocument, pStream);
}
CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
@@ -63,10 +62,9 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
const CFX_ByteString& bsType) {
if (!m_pPage->m_pResources) {
m_pPage->m_pResources =
- new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- m_pPage->m_pFormDict->SetReferenceFor(
- "Resources", m_pDocument,
- m_pDocument->AddIndirectObject(m_pPage->m_pResources));
+ m_pDocument->AddIndirectDictionary(m_pDocument->GetByteStringPool());
+ m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument,
+ m_pPage->m_pResources);
}
CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
if (!pResList) {
@@ -82,8 +80,9 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
}
idnum++;
}
- pResList->SetReferenceFor(name, m_pDocument,
- m_pDocument->AddIndirectObject(pResourceObj));
+ // TODO(tsepez): check |pResourceObj| ownership.
+ pResList->SetReferenceFor(name, m_pDocument, m_pDocument->AddIndirectObject(
+ UniqueObject(pResourceObj)));
return name;
}
@@ -170,8 +169,7 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) {
contentStream.LoadAllData(pStream);
ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
}
- CPDF_Stream* pStream = new CPDF_Stream;
+ CPDF_Stream* pStream = m_pDocument->AddIndirectStream();
pStream->SetData(buf.GetBuffer(), buf.GetLength());
- m_pPage->m_pFormDict->SetReferenceFor(
- "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream));
+ m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream);
}
diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp
index fae2b14449..5622b1dae7 100644
--- a/core/fpdfapi/edit/fpdf_edit_create.cpp
+++ b/core/fpdfapi/edit/fpdf_edit_create.cpp
@@ -1244,12 +1244,10 @@ int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) {
m_ObjectOffset[objnum] = 0;
return 0;
}
- if (WriteIndirectObj(pObj)) {
+ if (WriteIndirectObj(pObj))
return -1;
- }
- if (!bExistInMap) {
- m_pDocument->ReleaseIndirectObject(objnum);
- }
+ if (!bExistInMap)
+ m_pDocument->DeleteIndirectObject(objnum);
} else {
uint8_t* pBuffer;
uint32_t size;