summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-11-02 21:31:30 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-02 21:31:30 +0000
commitd7999f6a794207842544214d015af6f06322157c (patch)
tree300fbd43be94ea1b10268610296fd99cdf7c115d /core/fpdfapi/parser
parent0c9c70bdf9bcda1df54f1bc74016ce49dffb58b6 (diff)
downloadpdfium-d7999f6a794207842544214d015af6f06322157c.tar.xz
Move parsing logic from FPDF_DataAvail into CPDF_DataAvail.
Change-Id: Iacae9723e88eeae52154276b2478e4fd8c309c2d Reviewed-on: https://pdfium-review.googlesource.com/15512 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
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: