From d946f3011984755b14d7dcfb05d572e870f93f3f Mon Sep 17 00:00:00 2001 From: Jun Fang Date: Mon, 2 Nov 2015 13:45:35 +0800 Subject: Support linearized loading BUG=446715 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1353093003 . --- testing/embedder_test.cpp | 46 ++++++++++++++++++----- testing/embedder_test.h | 3 +- testing/resources/feature_linearized_loading.pdf | Bin 0 -> 11671 bytes 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 testing/resources/feature_linearized_loading.pdf (limited to 'testing') diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index b474955566..6151d73afd 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -11,6 +11,7 @@ #include #include +#include "../public/fpdf_dataavail.h" #include "../public/fpdf_text.h" #include "../public/fpdfview.h" #include "test_support.h" @@ -91,7 +92,8 @@ void EmbedderTest::TearDown() { free(file_contents_); } -bool EmbedderTest::OpenDocument(const std::string& filename) { +bool EmbedderTest::OpenDocument(const std::string& filename, + bool must_linearize) { file_contents_ = GetFileContents(filename.c_str(), &file_length_); if (!file_contents_) return false; @@ -108,18 +110,44 @@ bool EmbedderTest::OpenDocument(const std::string& filename) { hints_.AddSegment = Add_Segment; avail_ = FPDFAvail_Create(&file_avail_, &file_access_); - (void)FPDFAvail_IsDocAvail(avail_, &hints_); - if (!FPDFAvail_IsLinearized(avail_)) - document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); - else + if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) { document_ = FPDFAvail_GetDocument(avail_, nullptr); - - if (!document_) - return false; + if (!document_) { + return false; + } + int32_t nRet = PDF_DATA_NOTAVAIL; + while (nRet == PDF_DATA_NOTAVAIL) { + nRet = FPDFAvail_IsDocAvail(avail_, &hints_); + } + if (nRet == PDF_DATA_ERROR) { + return false; + } + nRet = FPDFAvail_IsFormAvail(avail_, &hints_); + if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { + return false; + } + int page_count = FPDF_GetPageCount(document_); + for (int i = 0; i < page_count; ++i) { + nRet = PDF_DATA_NOTAVAIL; + while (nRet == PDF_DATA_NOTAVAIL) { + nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); + } + if (nRet == PDF_DATA_ERROR) { + return false; + } + } + } else { + if (must_linearize) { + return false; + } + document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); + if (!document_) { + return false; + } + } (void)FPDF_GetDocPermissions(document_); - (void)FPDFAvail_IsFormAvail(avail_, &hints_); IPDF_JSPLATFORM* platform = static_cast(this); memset(platform, 0, sizeof(IPDF_JSPLATFORM)); diff --git a/testing/embedder_test.h b/testing/embedder_test.h index fb3ea428f1..035906d6c9 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -80,7 +80,8 @@ class EmbedderTest : public ::testing::Test, // Open the document specified by |filename|, and create its form fill // environment, or return false on failure. - virtual bool OpenDocument(const std::string& filename); + virtual bool OpenDocument(const std::string& filename, + bool must_linearize = false); // Perform JavaScript actions that are to run at document open time. virtual void DoOpenActions(); diff --git a/testing/resources/feature_linearized_loading.pdf b/testing/resources/feature_linearized_loading.pdf new file mode 100644 index 0000000000..e6995c516d Binary files /dev/null and b/testing/resources/feature_linearized_loading.pdf differ -- cgit v1.2.3