summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp31
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h5
2 files changed, 31 insertions, 5 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 4259d731cc..e72d7cdb19 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -106,10 +106,6 @@ CPDF_DataAvail::~CPDF_DataAvail() {
m_pHintTables.reset();
}
-void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) {
- m_pDocument = pDoc;
-}
-
CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail(
DownloadHints* pHints) {
if (!m_dwFileLen)
@@ -1044,6 +1040,33 @@ bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) {
return obj_avail.CheckAvail() == DocAvailStatus::DataAvailable;
}
+std::pair<CPDF_Parser::Error, std::unique_ptr<CPDF_Document>>
+CPDF_DataAvail::ParseDocument(const char* password) {
+ if (m_pDocument) {
+ // We already returned parsed document.
+ return std::make_pair(CPDF_Parser::HANDLER_ERROR, nullptr);
+ }
+ auto parser = pdfium::MakeUnique<CPDF_Parser>();
+ parser->SetPassword(password);
+ auto document = pdfium::MakeUnique<CPDF_Document>(std::move(parser));
+
+ CPDF_ReadValidator::Session read_session(GetValidator().Get());
+ CPDF_Parser::Error error = document->GetParser()->StartLinearizedParse(
+ GetFileRead(), document.get());
+
+ // Additional check, that all ok.
+ if (GetValidator()->has_read_problems()) {
+ NOTREACHED();
+ return std::make_pair(CPDF_Parser::HANDLER_ERROR, nullptr);
+ }
+
+ if (error != CPDF_Parser::SUCCESS)
+ return std::make_pair(error, nullptr);
+
+ m_pDocument = document.get();
+ return std::make_pair(CPDF_Parser::SUCCESS, std::move(document));
+}
+
CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {}
CPDF_DataAvail::PageNode::~PageNode() {}
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index 8916088556..001bf2280f 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -10,6 +10,7 @@
#include <map>
#include <memory>
#include <set>
+#include <utility>
#include <vector>
#include "core/fpdfapi/parser/cpdf_parser.h"
@@ -96,7 +97,6 @@ class CPDF_DataAvail final {
~CPDF_DataAvail();
DocAvailStatus IsDocAvail(DownloadHints* pHints);
- void SetDocument(CPDF_Document* pDoc);
DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints);
DocFormStatus IsFormAvail(DownloadHints* pHints);
DocLinearizationStatus IsLinearizedPDF();
@@ -105,6 +105,9 @@ class CPDF_DataAvail final {
CPDF_Dictionary* GetPage(int index);
RetainPtr<CPDF_ReadValidator> GetValidator() const;
+ std::pair<CPDF_Parser::Error, std::unique_ptr<CPDF_Document>> ParseDocument(
+ const char* password);
+
const CPDF_HintTables* GetHintTables() const { return m_pHintTables.get(); }
protected: