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

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: call FPDFAvail_IsDocAvail one more time Created 4 years, 6 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_);
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 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 } 2439 }
2439 if (needs_password) 2440 if (needs_password)
2440 GetPasswordAndLoad(); 2441 GetPasswordAndLoad();
2441 else 2442 else
2442 client_->DocumentLoadFailed(); 2443 client_->DocumentLoadFailed();
2443 } 2444 }
2444 2445
2445 bool PDFiumEngine::TryLoadingDoc(const std::string& password, 2446 bool PDFiumEngine::TryLoadingDoc(const std::string& password,
2446 bool* needs_password) { 2447 bool* needs_password) {
2447 *needs_password = false; 2448 *needs_password = false;
2448 if (doc_) 2449 if (doc_) {
2450 // This is probably not necessary, because it should have already been
2451 // called below in the |doc_| initialization path. However, the previous
2452 // call may have failed, so call it again for good measure.
2453 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
2449 return true; 2454 return true;
2455 }
2450 2456
2451 const char* password_cstr = nullptr; 2457 const char* password_cstr = nullptr;
2452 if (!password.empty()) { 2458 if (!password.empty()) {
2453 password_cstr = password.c_str(); 2459 password_cstr = password.c_str();
2454 password_tries_remaining_--; 2460 password_tries_remaining_--;
2455 } 2461 }
2456 if (doc_loader_.IsDocumentComplete() && 2462 if (doc_loader_.IsDocumentComplete() &&
2457 !FPDFAvail_IsLinearized(fpdf_availability_)) { 2463 !FPDFAvail_IsLinearized(fpdf_availability_)) {
2458 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); 2464 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr);
2459 } else { 2465 } else {
2460 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); 2466 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr);
2461 } 2467 }
2468 if (!doc_) {
2469 if (FPDF_GetLastError() == FPDF_ERR_PASSWORD)
2470 *needs_password = true;
2471 return false;
2472 }
2462 2473
2463 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) 2474 // Always call FPDFAvail_IsDocAvail() so PDFium initializes internal data
2464 *needs_password = true; 2475 // structures.
2465 2476 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
2466 return !!doc_; 2477 return true;
2467 } 2478 }
2468 2479
2469 void PDFiumEngine::GetPasswordAndLoad() { 2480 void PDFiumEngine::GetPasswordAndLoad() {
2470 getting_password_ = true; 2481 getting_password_ = true;
2471 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); 2482 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD);
2472 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( 2483 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput(
2473 &PDFiumEngine::OnGetPasswordComplete)); 2484 &PDFiumEngine::OnGetPasswordComplete));
2474 } 2485 }
2475 2486
2476 void PDFiumEngine::OnGetPasswordComplete(int32_t result, 2487 void PDFiumEngine::OnGetPasswordComplete(int32_t result,
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 FPDF_DOCUMENT doc = 3910 FPDF_DOCUMENT doc =
3900 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3911 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3901 if (!doc) 3912 if (!doc)
3902 return false; 3913 return false;
3903 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3914 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3904 FPDF_CloseDocument(doc); 3915 FPDF_CloseDocument(doc);
3905 return success; 3916 return success;
3906 } 3917 }
3907 3918
3908 } // namespace chrome_pdf 3919 } // 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