summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_data_avail.cpp
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-06-28 00:03:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-28 00:03:03 +0000
commit774c90d5ec92d2c58d821c445230d8cb71928dcb (patch)
treeed3d6bf9ebb646326c9d3729149957b4f33eaa0c /core/fpdfapi/parser/cpdf_data_avail.cpp
parentb8f24bb50582436c7fb261b5021f7af6813f3968 (diff)
downloadpdfium-774c90d5ec92d2c58d821c445230d8cb71928dcb.tar.xz
Use UnownedPtr for document within CPDF_XXXAvail.
Change-Id: I9ded1664564c330132f43047293e18696d77fc7d Reviewed-on: https://pdfium-review.googlesource.com/36310 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_data_avail.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 95db3d81c0..89b576bdea 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -70,6 +70,17 @@ class HintsScope {
UnownedPtr<CPDF_ReadValidator> validator_;
};
+class CPDF_DocumentForAvail : public CPDF_Document {
+ public:
+ explicit CPDF_DocumentForAvail(CPDF_DataAvail* avail) : m_pAvail(avail) {
+ DCHECK(avail);
+ }
+ ~CPDF_DocumentForAvail() override { m_pAvail->BeforeDocumentDestroyed(); }
+
+ private:
+ UnownedPtr<CPDF_DataAvail> m_pAvail;
+};
+
} // namespace
CPDF_DataAvail::FileAvail::~FileAvail() {}
@@ -89,6 +100,14 @@ CPDF_DataAvail::~CPDF_DataAvail() {
m_pHintTables.reset();
}
+void CPDF_DataAvail::BeforeDocumentDestroyed() {
+ m_pDocument = nullptr;
+ m_pFormAvail.reset();
+ m_PagesArray.clear();
+ m_PagesObjAvail.clear();
+ m_PagesResourcesAvail.clear();
+}
+
CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail(
DownloadHints* pHints) {
if (!m_dwFileLen)
@@ -816,7 +835,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail(
auto page_num_obj = std::make_pair(
dwPage, pdfium::MakeUnique<CPDF_PageObjectAvail>(
- GetValidator().Get(), m_pDocument, pPageDict));
+ GetValidator().Get(), m_pDocument.Get(), pPageDict));
CPDF_PageObjectAvail* page_obj_avail =
m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get();
@@ -868,7 +887,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail(
{
auto page_num_obj = std::make_pair(
dwPage, pdfium::MakeUnique<CPDF_PageObjectAvail>(
- GetValidator().Get(), m_pDocument, pPageDict));
+ GetValidator().Get(), m_pDocument.Get(), pPageDict));
CPDF_PageObjectAvail* page_obj_avail =
m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get();
const DocAvailStatus status = page_obj_avail->CheckAvail();
@@ -900,8 +919,9 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckResources(
CPDF_PageObjectAvail* resource_avail =
m_PagesResourcesAvail
.insert(std::make_pair(
- resources, pdfium::MakeUnique<CPDF_PageObjectAvail>(
- GetValidator().Get(), m_pDocument, resources)))
+ resources,
+ pdfium::MakeUnique<CPDF_PageObjectAvail>(
+ GetValidator().Get(), m_pDocument.Get(), resources)))
.first->second.get();
return resource_avail->CheckAvail();
}
@@ -944,7 +964,8 @@ CPDF_Dictionary* CPDF_DataAvail::GetPageDictionary(int index) const {
// Page object already can be parsed in document.
if (!m_pDocument->GetIndirectObject(dwObjNum)) {
m_pDocument->ReplaceIndirectObjectIfHigherGeneration(
- dwObjNum, ParseIndirectObjectAt(szPageStartPos, dwObjNum, m_pDocument));
+ dwObjNum,
+ ParseIndirectObjectAt(szPageStartPos, dwObjNum, m_pDocument.Get()));
}
if (!ValidatePage(index))
return nullptr;
@@ -979,7 +1000,7 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::CheckAcroForm() {
return FormNotExist;
m_pFormAvail = pdfium::MakeUnique<CPDF_PageObjectAvail>(
- GetValidator().Get(), m_pDocument, pAcroForm);
+ GetValidator().Get(), m_pDocument.Get(), pAcroForm);
}
switch (m_pFormAvail->CheckAvail()) {
case DocAvailStatus::DataError:
@@ -999,7 +1020,8 @@ bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) const {
auto* pPageDict = m_pDocument->GetPageDictionary(safePage.ValueOrDie());
if (!pPageDict)
return false;
- CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument, pPageDict);
+ CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument.Get(),
+ pPageDict);
return obj_avail.CheckAvail() == DocAvailStatus::DataAvailable;
}
@@ -1009,7 +1031,7 @@ CPDF_DataAvail::ParseDocument(const char* password) {
// We already returned parsed document.
return std::make_pair(CPDF_Parser::HANDLER_ERROR, nullptr);
}
- auto document = pdfium::MakeUnique<CPDF_Document>();
+ auto document = pdfium::MakeUnique<CPDF_DocumentForAvail>(this);
CPDF_ReadValidator::Session read_session(GetValidator().Get());
CPDF_Parser::Error error =