Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1552603002: Support loading complete linearized PDF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 doc_loader_.document_size()); 1149 doc_loader_.document_size());
1150 } 1150 }
1151 1151
1152 void PDFiumEngine::OnDocumentComplete() { 1152 void PDFiumEngine::OnDocumentComplete() {
1153 if (!doc_ || !form_) { 1153 if (!doc_ || !form_) {
1154 file_access_.m_FileLen = doc_loader_.document_size(); 1154 file_access_.m_FileLen = doc_loader_.document_size();
1155 LoadDocument(); 1155 LoadDocument();
1156 return; 1156 return;
1157 } 1157 }
1158 1158
1159 FinishLoadingDocument();
1160 }
1161
1162 void PDFiumEngine::FinishLoadingDocument() {
1163 DCHECK(doc_loader_.IsDocumentComplete() && doc_);
1164
1159 bool need_update = false; 1165 bool need_update = false;
1160 for (size_t i = 0; i < pages_.size(); ++i) { 1166 for (size_t i = 0; i < pages_.size(); ++i) {
1161 if (pages_[i]->available()) 1167 if (pages_[i]->available())
1162 continue; 1168 continue;
1163 1169
1164 pages_[i]->set_available(true); 1170 pages_[i]->set_available(true);
1165 // We still need to call IsPageAvail() even if the whole document is 1171 // We still need to call IsPageAvail() even if the whole document is
1166 // already downloaded. 1172 // already downloaded.
1167 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); 1173 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_);
1168 need_update = true; 1174 need_update = true;
1169 if (IsPageVisible(i)) 1175 if (IsPageVisible(i))
1170 client_->Invalidate(GetPageScreenRect(i)); 1176 client_->Invalidate(GetPageScreenRect(i));
1171 } 1177 }
1172 if (need_update) 1178 if (need_update)
1173 LoadPageInfo(true); 1179 LoadPageInfo(true);
1174 1180
1175 FinishLoadingDocument();
1176 }
1177
1178 void PDFiumEngine::FinishLoadingDocument() {
1179 DCHECK(doc_loader_.IsDocumentComplete() && doc_);
1180 if (called_do_document_action_) 1181 if (called_do_document_action_)
1181 return; 1182 return;
1182 called_do_document_action_ = true; 1183 called_do_document_action_ = true;
1183 1184
1184 // These can only be called now, as the JS might end up needing a page. 1185 // These can only be called now, as the JS might end up needing a page.
1185 FORM_DoDocumentJSAction(form_); 1186 FORM_DoDocumentJSAction(form_);
1186 FORM_DoDocumentOpenAction(form_); 1187 FORM_DoDocumentOpenAction(form_);
1187 if (most_visible_page_ != -1) { 1188 if (most_visible_page_ != -1) {
1188 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); 1189 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage();
1189 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); 1190 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN);
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 2661
2661 for (int i = 0; i < page_count; ++i) { 2662 for (int i = 0; i < page_count; ++i) {
2662 // Center pages relative to the entire document. 2663 // Center pages relative to the entire document.
2663 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); 2664 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2);
2664 pp::Rect page_rect(page_rects[i]); 2665 pp::Rect page_rect(page_rects[i]);
2665 page_rect.Inset(kPageShadowLeft, kPageShadowTop, 2666 page_rect.Inset(kPageShadowLeft, kPageShadowTop,
2666 kPageShadowRight, kPageShadowBottom); 2667 kPageShadowRight, kPageShadowBottom);
2667 if (reload) { 2668 if (reload) {
2668 pages_[i]->set_rect(page_rect); 2669 pages_[i]->set_rect(page_rect);
2669 } else { 2670 } else {
2670 pages_.push_back(new PDFiumPage(this, i, page_rect, doc_complete)); 2671 // The page is marked as not being available even if doc_complete is true
Lei Zhang 2015/12/28 23:55:02 Please refer to variables are |var_name|.
spelchat 2015/12/29 00:04:03 Done.
2672 // because FPDFAvail_IsPageAvail still has to be called for this page,
Lei Zhang 2015/12/28 23:55:02 If you refer to functions as FuncName(), then it's
spelchat 2015/12/29 00:04:03 Done.
2673 // which will be done in FinishLoadingDocument.
2674 pages_.push_back(new PDFiumPage(this, i, page_rect, false));
2671 } 2675 }
2672 } 2676 }
2673 2677
2674 CalculateVisiblePages(); 2678 CalculateVisiblePages();
2675 if (document_size_ != old_document_size) 2679 if (document_size_ != old_document_size)
2676 client_->DocumentSizeUpdated(document_size_); 2680 client_->DocumentSizeUpdated(document_size_);
2677 } 2681 }
2678 2682
2679 void PDFiumEngine::CalculateVisiblePages() { 2683 void PDFiumEngine::CalculateVisiblePages() {
2680 // Clear pending requests queue, since it may contain requests to the pages 2684 // Clear pending requests queue, since it may contain requests to the pages
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 double* height) { 4003 double* height) {
4000 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4004 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4001 if (!doc) 4005 if (!doc)
4002 return false; 4006 return false;
4003 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4007 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4004 FPDF_CloseDocument(doc); 4008 FPDF_CloseDocument(doc);
4005 return success; 4009 return success;
4006 } 4010 }
4007 4011
4008 } // namespace chrome_pdf 4012 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698