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

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

Issue 2080313003: M52: PDF: Always call FPDFAvail_IsDocAvail() when loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: 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 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 if (needs_password) 2411 if (needs_password)
2411 GetPasswordAndLoad(); 2412 GetPasswordAndLoad();
2412 else 2413 else
2413 client_->DocumentLoadFailed(); 2414 client_->DocumentLoadFailed();
2414 } 2415 }
2415 2416
2416 bool PDFiumEngine::TryLoadingDoc(bool with_password, 2417 bool PDFiumEngine::TryLoadingDoc(bool with_password,
2417 const std::string& password, 2418 const std::string& password,
2418 bool* needs_password) { 2419 bool* needs_password) {
2419 *needs_password = false; 2420 *needs_password = false;
2420 if (doc_) 2421 if (doc_) {
2422 // This is probably not necessary, because it should have already been
2423 // called below in the |doc_| initialization path. However, the previous
2424 // call may have failed, so call it again for good measure.
2425 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
2421 return true; 2426 return true;
2427 }
2422 2428
2423 const char* password_cstr = nullptr; 2429 const char* password_cstr = nullptr;
2424 if (with_password) { 2430 if (with_password) {
2425 password_cstr = password.c_str(); 2431 password_cstr = password.c_str();
2426 password_tries_remaining_--; 2432 password_tries_remaining_--;
2427 } 2433 }
2428 if (doc_loader_.IsDocumentComplete() && 2434 if (doc_loader_.IsDocumentComplete() &&
2429 !FPDFAvail_IsLinearized(fpdf_availability_)) { 2435 !FPDFAvail_IsLinearized(fpdf_availability_)) {
2430 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); 2436 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr);
2431 } else { 2437 } else {
2432 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); 2438 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr);
2433 } 2439 }
2440 if (!doc_) {
2441 if (FPDF_GetLastError() == FPDF_ERR_PASSWORD)
2442 *needs_password = true;
2443 return false;
2444 }
2434 2445
2435 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) 2446 // Always call FPDFAvail_IsDocAvail() so PDFium initializes internal data
2436 *needs_password = true; 2447 // structures.
2437 2448 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_);
2438 return !!doc_; 2449 return true;
2439 } 2450 }
2440 2451
2441 void PDFiumEngine::GetPasswordAndLoad() { 2452 void PDFiumEngine::GetPasswordAndLoad() {
2442 getting_password_ = true; 2453 getting_password_ = true;
2443 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); 2454 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD);
2444 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( 2455 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput(
2445 &PDFiumEngine::OnGetPasswordComplete)); 2456 &PDFiumEngine::OnGetPasswordComplete));
2446 } 2457 }
2447 2458
2448 void PDFiumEngine::OnGetPasswordComplete(int32_t result, 2459 void PDFiumEngine::OnGetPasswordComplete(int32_t result,
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 FPDF_DOCUMENT doc = 3888 FPDF_DOCUMENT doc =
3878 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3889 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3879 if (!doc) 3890 if (!doc)
3880 return false; 3891 return false;
3881 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3892 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3882 FPDF_CloseDocument(doc); 3893 FPDF_CloseDocument(doc);
3883 return success; 3894 return success;
3884 } 3895 }
3885 3896
3886 } // namespace chrome_pdf 3897 } // 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