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

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

Issue 2006793003: PDF: Always call FPDFAvail_IsDocAvail() when loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better fix? Created 4 years, 7 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 | « pdf/pdfium/pdfium_engine.h ('k') | 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 EnumFonts, 291 EnumFonts,
292 MapFont, 292 MapFont,
293 0, 293 0,
294 GetFontData, 294 GetFontData,
295 0, 295 0,
296 0, 296 0,
297 DeleteFont 297 DeleteFont
298 }; 298 };
299 #endif // defined(OS_LINUX) 299 #endif // defined(OS_LINUX)
300 300
301 PDFiumEngine* g_engine_for_unsupported; 301 PDFiumEngine* g_engine_for_unsupported = nullptr;
302 302
303 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { 303 void Unsupported_Handler(UNSUPPORT_INFO*, int type) {
304 if (!g_engine_for_unsupported) { 304 if (!g_engine_for_unsupported) {
305 NOTREACHED(); 305 NOTREACHED();
306 return; 306 return;
307 } 307 }
308 308
309 g_engine_for_unsupported->UnsupportedFeature(type); 309 g_engine_for_unsupported->UnsupportedFeature(type);
310 } 310 }
311 311
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 if (!FPDFAvail_IsLinearized(fpdf_availability_)) { 1042 if (!FPDFAvail_IsLinearized(fpdf_availability_)) {
1043 doc_loader_.RequestData(0, doc_loader_.document_size()); 1043 doc_loader_.RequestData(0, doc_loader_.document_size());
1044 return; 1044 return;
1045 } 1045 }
1046 1046
1047 LoadDocument(); 1047 LoadDocument();
1048 } 1048 }
1049 1049
1050 void PDFiumEngine::OnPendingRequestComplete() { 1050 void PDFiumEngine::OnPendingRequestComplete() {
1051 if (!doc_ || !form_) { 1051 if (!doc_ || !form_) {
1052 DCHECK(fpdf_availability_);
Lei Zhang 2016/05/25 17:16:36 I'm pretty sure OnPartialDocumentLoaded() has to b
Wei Li 2016/05/25 22:37:38 Acknowledged.
1052 LoadDocument(); 1053 LoadDocument();
1053 return; 1054 return;
1054 } 1055 }
1055 1056
1056 // LoadDocument() will result in |pending_pages_| being reset so there's no 1057 // LoadDocument() will result in |pending_pages_| being reset so there's no
1057 // need to run the code below in that case. 1058 // need to run the code below in that case.
1058 bool update_pages = false; 1059 bool update_pages = false;
1059 std::vector<int> still_pending; 1060 std::vector<int> still_pending;
1060 for (int pending_page : pending_pages_) { 1061 for (int pending_page : pending_pages_) {
1061 if (CheckPageAvailable(pending_page, &still_pending)) { 1062 if (CheckPageAvailable(pending_page, &still_pending)) {
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 if (!password.empty()) { 2424 if (!password.empty()) {
2424 password_cstr = password.c_str(); 2425 password_cstr = password.c_str();
2425 password_tries_remaining_--; 2426 password_tries_remaining_--;
2426 } 2427 }
2427 if (doc_loader_.IsDocumentComplete() && 2428 if (doc_loader_.IsDocumentComplete() &&
2428 !FPDFAvail_IsLinearized(fpdf_availability_)) { 2429 !FPDFAvail_IsLinearized(fpdf_availability_)) {
2429 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); 2430 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr);
2430 } else { 2431 } else {
2431 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); 2432 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr);
2432 } 2433 }
2434 if (!doc_) {
2435 if (FPDF_GetLastError() == FPDF_ERR_PASSWORD)
2436 *needs_password = true;
2437 return false;
2438 }
2433 2439
2434 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) 2440 // Always call FPDFAvail_IsDocAvail() so PDFium initializes internal data
2435 *needs_password = true; 2441 // structures.
2436 2442 int avail = FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
Lei Zhang 2016/05/25 17:16:36 I decided to (potentially) call this a second time
Wei Li 2016/05/25 22:37:38 Would this approach be fragile? In samples/pdfium_
Lei Zhang 2016/06/14 17:53:56 Whether FPDFAvail_IsDocAvail() ends up reading the
Wei Li 2016/06/14 23:33:42 I think the fix is in right direction. But we need
2437 return !!doc_; 2443 DCHECK_EQ(PDF_DATA_AVAIL, avail);
2444 return true;
2438 } 2445 }
2439 2446
2440 void PDFiumEngine::GetPasswordAndLoad() { 2447 void PDFiumEngine::GetPasswordAndLoad() {
2441 getting_password_ = true; 2448 getting_password_ = true;
2442 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); 2449 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD);
2443 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( 2450 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput(
2444 &PDFiumEngine::OnGetPasswordComplete)); 2451 &PDFiumEngine::OnGetPasswordComplete));
2445 } 2452 }
2446 2453
2447 void PDFiumEngine::OnGetPasswordComplete(int32_t result, 2454 void PDFiumEngine::OnGetPasswordComplete(int32_t result,
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
3870 FPDF_DOCUMENT doc = 3877 FPDF_DOCUMENT doc =
3871 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3878 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3872 if (!doc) 3879 if (!doc)
3873 return false; 3880 return false;
3874 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3881 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3875 FPDF_CloseDocument(doc); 3882 FPDF_CloseDocument(doc);
3876 return success; 3883 return success;
3877 } 3884 }
3878 3885
3879 } // namespace chrome_pdf 3886 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698