diff options
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 18 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 9 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.h | 4 |
3 files changed, 13 insertions, 18 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 89b576bdea..a251d6ff61 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -70,17 +70,6 @@ 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() {} @@ -98,9 +87,11 @@ CPDF_DataAvail::CPDF_DataAvail( CPDF_DataAvail::~CPDF_DataAvail() { m_pHintTables.reset(); + if (m_pDocument) + m_pDocument->RemoveObserver(this); } -void CPDF_DataAvail::BeforeDocumentDestroyed() { +void CPDF_DataAvail::OnObservableDestroyed() { m_pDocument = nullptr; m_pFormAvail.reset(); m_PagesArray.clear(); @@ -1031,7 +1022,8 @@ 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_DocumentForAvail>(this); + auto document = pdfium::MakeUnique<CPDF_Document>(); + document->AddObserver(this); CPDF_ReadValidator::Session read_session(GetValidator().Get()); CPDF_Parser::Error error = diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 3c45116088..ea831d94db 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -13,13 +13,13 @@ #include <utility> #include <vector> +#include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_syntax_parser.h" #include "core/fxcrt/unowned_ptr.h" class CPDF_CrossRefAvail; class CPDF_Dictionary; -class CPDF_Document; class CPDF_HintTables; class CPDF_IndirectObjectHolder; class CPDF_LinearizedHeader; @@ -50,7 +50,7 @@ enum PDF_PAGENODE_TYPE { PDF_PAGENODE_ARRAY, }; -class CPDF_DataAvail final { +class CPDF_DataAvail final : public CPDF_Document::Observer { public: // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts @@ -95,9 +95,10 @@ class CPDF_DataAvail final { CPDF_DataAvail(FileAvail* pFileAvail, const RetainPtr<IFX_SeekableReadStream>& pFileRead, bool bSupportHintTable); - ~CPDF_DataAvail(); + ~CPDF_DataAvail() override; - void BeforeDocumentDestroyed(); + // CPDF_Document::Observer: + void OnObservableDestroyed() override; DocAvailStatus IsDocAvail(DownloadHints* pHints); DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints); diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 401f37d0cf..a40993da17 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -18,6 +18,7 @@ #include "core/fpdfapi/parser/cpdf_object.h" #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfdoc/cpdf_linklist.h" +#include "core/fxcrt/observable.h" #include "core/fxcrt/retain_ptr.h" class CFX_Font; @@ -40,7 +41,8 @@ class JBig2_DocumentContext; #define FPDFPERM_FILL_FORM 0x0100 #define FPDFPERM_EXTRACT_ACCESS 0x0200 -class CPDF_Document : public CPDF_Parser::ParsedObjectsHolder { +class CPDF_Document : public Observable<CPDF_Document>, + public CPDF_Parser::ParsedObjectsHolder { public: // Type from which the XFA extension can subclass itself. class Extension { |