Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index 10f11d126bab753e53a370d020b9b6767b8e47c5..378e90492f0bf2454b0eab592c846c8c2da53e46 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -1113,8 +1113,10 @@ std::string PDFiumEngine::GetMetadata(const std::string& key) { |
| void PDFiumEngine::OnPartialDocumentLoaded() { |
| file_access_.m_FileLen = doc_loader_.document_size(); |
| - fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
| - DCHECK(fpdf_availability_); |
| + if (!fpdf_availability_) { |
|
Lei Zhang
2016/01/28 23:17:58
I haven't checked the possible call orders between
|
| + fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
| + DCHECK(fpdf_availability_); |
| + } |
| // Currently engine does not deal efficiently with some non-linearized files. |
| // See http://code.google.com/p/chromium/issues/detail?id=59400 |
| @@ -1157,6 +1159,10 @@ void PDFiumEngine::OnNewDataAvailable() { |
| void PDFiumEngine::OnDocumentComplete() { |
| if (!doc_ || !form_) { |
| file_access_.m_FileLen = doc_loader_.document_size(); |
| + if (!fpdf_availability_) { |
| + fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
| + DCHECK(fpdf_availability_); |
| + } |
| LoadDocument(); |
| return; |
| } |
| @@ -2501,10 +2507,12 @@ bool PDFiumEngine::TryLoadingDoc(bool with_password, |
| password_cstr = password.c_str(); |
| password_tries_remaining_--; |
| } |
| - if (doc_loader_.IsDocumentComplete()) |
| + if (doc_loader_.IsDocumentComplete() && |
| + !FPDFAvail_IsLinearized(fpdf_availability_)) { |
| doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); |
| - else |
| + } else { |
| doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); |
| + } |
| if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) |
| *needs_password = true; |