summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorart-snake <art-snake@yandex-team.ru>2016-11-09 21:32:46 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-09 21:32:46 -0800
commit61f8e9c5aeb0d8cb5477e0248b685214746bada7 (patch)
tree43c01abc09c72d088b5f79b54fbec37c0a60d5a3 /fpdfsdk
parent3f8cb532c93bd2839073ed4949d051245de5a4cb (diff)
downloadpdfium-61f8e9c5aeb0d8cb5477e0248b685214746bada7.tar.xz
Do not load main cross ref table for first page in linearized pdf.
For the first page in linearized PDFs, it is not necessary to load the main xref table, because it have separate special xref table in the file header. This decreasing the time to show first page in PDF plugin. Review-Url: https://codereview.chromium.org/2483633002
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_dataavail_embeddertest.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
index 47ba54bcde..cc95c1b177 100644
--- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -45,13 +45,22 @@ class TestAsyncLoader : public FX_DOWNLOADHINTS, FX_FILEAVAIL {
return requested_segments_;
}
- void ClearRequestedSegments() { requested_segments_.clear(); }
+ size_t max_requested_bound() const { return max_requested_bound_; }
+
+ void ClearRequestedSegments() {
+ requested_segments_.clear();
+ max_requested_bound_ = 0;
+ }
bool is_new_data_available() const { return is_new_data_available_; }
void set_is_new_data_available(bool is_new_data_available) {
is_new_data_available_ = is_new_data_available;
}
+ size_t max_already_available_bound() const {
+ return available_ranges_.empty() ? 0 : available_ranges_.rbegin()->second;
+ }
+
private:
void SetDataAvailable(size_t start, size_t size) {
if (size == 0)
@@ -109,6 +118,7 @@ class TestAsyncLoader : public FX_DOWNLOADHINTS, FX_FILEAVAIL {
void AddSegmentImpl(size_t offset, size_t size) {
requested_segments_.push_back(std::make_pair(offset, size));
+ max_requested_bound_ = std::max(max_requested_bound_, offset + size);
}
bool IsDataAvailImpl(size_t offset, size_t size) {
@@ -143,6 +153,7 @@ class TestAsyncLoader : public FX_DOWNLOADHINTS, FX_FILEAVAIL {
std::unique_ptr<char, pdfium::FreeDeleter> file_contents_;
size_t file_length_;
std::vector<std::pair<size_t, size_t>> requested_segments_;
+ size_t max_requested_bound_ = 0;
bool is_new_data_available_ = true;
using Range = std::pair<size_t, size_t>;
@@ -185,3 +196,43 @@ TEST_F(FPDFDataAvailEmbeddertest, LoadUsingHintTables) {
EXPECT_TRUE(page);
UnloadPage(page);
}
+
+TEST_F(FPDFDataAvailEmbeddertest,
+ DoNotLoadMainCrossRefForFirstPageIfLinearized) {
+ TestAsyncLoader loader("feature_linearized_loading.pdf");
+ avail_ = FPDFAvail_Create(loader.file_avail(), loader.file_access());
+ ASSERT_EQ(PDF_DATA_AVAIL, FPDFAvail_IsDocAvail(avail_, loader.hints()));
+ document_ = FPDFAvail_GetDocument(avail_, nullptr);
+ ASSERT_TRUE(document_);
+ const int first_page_num = FPDFAvail_GetFirstPageNum(document_);
+
+ // The main cross ref table should not be processed.
+ // (It is always at file end)
+ EXPECT_GT(loader.file_access()->m_FileLen,
+ loader.max_already_available_bound());
+
+ // Prevent access to non requested data to coerce the parser to send new
+ // request for non available (non requested before) data.
+ loader.set_is_new_data_available(false);
+ FPDFAvail_IsPageAvail(avail_, first_page_num, loader.hints());
+
+ // The main cross ref table should not be requested.
+ // (It is always at file end)
+ EXPECT_GT(loader.file_access()->m_FileLen, loader.max_requested_bound());
+
+ // Allow parse page.
+ loader.set_is_new_data_available(true);
+ ASSERT_EQ(PDF_DATA_AVAIL,
+ FPDFAvail_IsPageAvail(avail_, first_page_num, loader.hints()));
+
+ // The main cross ref table should not be processed.
+ // (It is always at file end)
+ EXPECT_GT(loader.file_access()->m_FileLen,
+ loader.max_already_available_bound());
+
+ // Prevent loading data, while page loading.
+ loader.set_is_new_data_available(false);
+ FPDF_PAGE page = LoadPage(first_page_num);
+ EXPECT_TRUE(page);
+ UnloadPage(page);
+}