Index: pdf/pdfium/pdfium_engine.cc |
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
index 17ef03f6a74428bc7d918c7b84c373affcdc221e..b3a6d9523d1c2a86b8e58b03d9b27b302a5bdcbc 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; |
} |
@@ -2445,8 +2446,13 @@ void PDFiumEngine::LoadDocument() { |
bool PDFiumEngine::TryLoadingDoc(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 (!password.empty()) { |
@@ -2459,11 +2465,16 @@ bool PDFiumEngine::TryLoadingDoc(const std::string& 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() { |