From d7d4d710ba90e41bc9295e87a63db57f093bd3ad Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 20 Jun 2016 10:56:51 -0700 Subject: [PATCH] M52: PDF: Always call FPDFAvail_IsDocAvail() when loading. BUG=613704 Review-Url: https://codereview.chromium.org/2006793003 Cr-Commit-Position: refs/heads/master@{#400286} (cherry picked from commit 0968faa3214a03bc763d15fd66943ff3bcaf75d5) Review URL: https://codereview.chromium.org/2080313003 . Cr-Commit-Position: refs/branch-heads/2743@{#406} Cr-Branched-From: 2b3ae3b8090361f8af5a611712fc1a5ab2de53cb-refs/heads/master@{#394939} --- pdf/pdfium/pdfium_engine.cc | 23 +++++++++++++++++------ pdf/pdfium/pdfium_engine.h | 14 ++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index ac00af5c590d3..eedf9f706b1be 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -298,7 +298,7 @@ FPDF_SYSFONTINFO g_font_info = { }; #endif // defined(OS_LINUX) -PDFiumEngine* g_engine_for_unsupported; +PDFiumEngine* g_engine_for_unsupported = nullptr; void Unsupported_Handler(UNSUPPORT_INFO*, int type) { if (!g_engine_for_unsupported) { @@ -1049,6 +1049,7 @@ void PDFiumEngine::OnPartialDocumentLoaded() { void PDFiumEngine::OnPendingRequestComplete() { if (!doc_ || !form_) { + DCHECK(fpdf_availability_); LoadDocument(); return; } @@ -2417,8 +2418,13 @@ bool PDFiumEngine::TryLoadingDoc(bool with_password, const std::string& password, bool* needs_password) { *needs_password = false; - if (doc_) + if (doc_) { + // This is probably not necessary, because it should have already been + // called below in the |doc_| initialization path. However, the previous + // call may have failed, so call it again for good measure. + FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_); return true; + } const char* password_cstr = nullptr; if (with_password) { @@ -2431,11 +2437,16 @@ bool PDFiumEngine::TryLoadingDoc(bool with_password, } else { doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); } + if (!doc_) { + if (FPDF_GetLastError() == FPDF_ERR_PASSWORD) + *needs_password = true; + return false; + } - if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) - *needs_password = true; - - return !!doc_; + // Always call FPDFAvail_IsDocAvail() so PDFium initializes internal data + // structures. + FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_); + return true; } void PDFiumEngine::GetPasswordAndLoad() { diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index ec3c80dcce937..dcfbe3d132b43 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -212,7 +212,7 @@ class PDFiumEngine : public PDFEngine, const std::string& password, bool* needs_password); - // Ask the user for the document password and then continue loading the + // Asks the user for the document password and then continue loading the // document. void GetPasswordAndLoad(); @@ -225,17 +225,19 @@ class PDFiumEngine : public PDFEngine, void ContinueLoadingDocument(bool has_password, const std::string& password); - // Finish loading the document and notify the client that the document has - // been loaded. This should only be run after |doc_| has been loaded and the - // document is fully downloaded. If this has been run once, it will result in - // a no-op. + // Finishes loading the document. Recalculate the document size if there were + // pages that were not previously available. + // Also notifies the client that the document has been loaded. + // This should only be called after |doc_| has been loaded and the document is + // fully downloaded. + // If this has been run once, it will not notify the client again. void FinishLoadingDocument(); // Loads information about the pages in the document and calculate the // document size. void LoadPageInfo(bool reload); - // Calculate which pages should be displayed right now. + // Calculates which pages should be displayed right now. void CalculateVisiblePages(); // Returns true iff the given page index is visible. CalculateVisiblePages