Pass retained arguments to CPDF_PageObjectHolder.
-- update wording of one nearby comment.
Change-Id: I8bcbdf549509f2b83e0d1a5190a5e9f9bd13d7b1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98592
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 4ced722..9afda3f 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -180,9 +180,7 @@
const ByteString& bsType) const {
DCHECK(pResource);
if (!m_pObjHolder->GetResources()) {
- // TODO(tsepez): pass retained argument.
- m_pObjHolder->SetResources(
- m_pDocument->NewIndirect<CPDF_Dictionary>().Get());
+ m_pObjHolder->SetResources(m_pDocument->NewIndirect<CPDF_Dictionary>());
m_pObjHolder->GetMutableDict()->SetNewFor<CPDF_Reference>(
"Resources", m_pDocument.Get(),
m_pObjHolder->GetResources()->GetObjNum());
diff --git a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
index e2305ce..a940a2a 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
@@ -49,10 +49,10 @@
CPDF_PageContentManager::~CPDF_PageContentManager() = default;
-// TODO(tsepez): return retained reference.
-CPDF_Stream* CPDF_PageContentManager::GetStreamByIndex(size_t stream_index) {
+RetainPtr<CPDF_Stream> CPDF_PageContentManager::GetStreamByIndex(
+ size_t stream_index) {
if (contents_stream_)
- return stream_index == 0 ? contents_stream_.Get() : nullptr;
+ return stream_index == 0 ? contents_stream_ : nullptr;
if (!contents_array_)
return nullptr;
@@ -62,7 +62,7 @@
if (!stream_reference)
return nullptr;
- return stream_reference->GetMutableDirect()->AsMutableStream();
+ return ToStream(stream_reference->GetMutableDirect());
}
size_t CPDF_PageContentManager::AddStream(fxcrt::ostringstream* buf) {
diff --git a/core/fpdfapi/edit/cpdf_pagecontentmanager.h b/core/fpdfapi/edit/cpdf_pagecontentmanager.h
index bbc8f2b..60e2146 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentmanager.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentmanager.h
@@ -22,8 +22,8 @@
~CPDF_PageContentManager();
// Gets the Content stream at a given index. If Contents is a single stream
- // rather than an array, it is considered to be at index 0.
- CPDF_Stream* GetStreamByIndex(size_t stream_index);
+ // rather than an array, it is retrievable at index 0.
+ RetainPtr<CPDF_Stream> GetStreamByIndex(size_t stream_index);
// Adds a new Content stream. Its index in the array will be returned, or 0
// if Contents is not an array, but only a single stream.
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h
index 3453107..231e150 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.h
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.h
@@ -14,6 +14,7 @@
#include <map>
#include <memory>
#include <set>
+#include <utility>
#include <vector>
#include "core/fpdfapi/page/cpdf_transparency.h"
@@ -72,7 +73,9 @@
RetainPtr<CPDF_Dictionary> GetMutableDict() { return m_pDict; }
const CPDF_Dictionary* GetResources() const { return m_pResources.Get(); }
RetainPtr<CPDF_Dictionary> GetMutableResources() { return m_pResources; }
- void SetResources(CPDF_Dictionary* pDict) { m_pResources.Reset(pDict); }
+ void SetResources(RetainPtr<CPDF_Dictionary> pDict) {
+ m_pResources = std::move(pDict);
+ }
const CPDF_Dictionary* GetPageResources() const {
return m_pPageResources.Get();
}