OLD | NEW |
---|---|
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 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 bool PDFiumEngine::IsProgressiveLoad() { | 1106 bool PDFiumEngine::IsProgressiveLoad() { |
1107 return doc_loader_.is_partial_document(); | 1107 return doc_loader_.is_partial_document(); |
1108 } | 1108 } |
1109 | 1109 |
1110 std::string PDFiumEngine::GetMetadata(const std::string& key) { | 1110 std::string PDFiumEngine::GetMetadata(const std::string& key) { |
1111 return GetDocumentMetadata(doc(), key); | 1111 return GetDocumentMetadata(doc(), key); |
1112 } | 1112 } |
1113 | 1113 |
1114 void PDFiumEngine::OnPartialDocumentLoaded() { | 1114 void PDFiumEngine::OnPartialDocumentLoaded() { |
1115 file_access_.m_FileLen = doc_loader_.document_size(); | 1115 file_access_.m_FileLen = doc_loader_.document_size(); |
1116 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); | 1116 if (!fpdf_availability_) { |
Lei Zhang
2016/01/28 23:17:58
I haven't checked the possible call orders between
| |
1117 DCHECK(fpdf_availability_); | 1117 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
1118 DCHECK(fpdf_availability_); | |
1119 } | |
1118 | 1120 |
1119 // Currently engine does not deal efficiently with some non-linearized files. | 1121 // Currently engine does not deal efficiently with some non-linearized files. |
1120 // See http://code.google.com/p/chromium/issues/detail?id=59400 | 1122 // See http://code.google.com/p/chromium/issues/detail?id=59400 |
1121 // To improve user experience we download entire file for non-linearized PDF. | 1123 // To improve user experience we download entire file for non-linearized PDF. |
1122 if (!FPDFAvail_IsLinearized(fpdf_availability_)) { | 1124 if (!FPDFAvail_IsLinearized(fpdf_availability_)) { |
1123 doc_loader_.RequestData(0, doc_loader_.document_size()); | 1125 doc_loader_.RequestData(0, doc_loader_.document_size()); |
1124 return; | 1126 return; |
1125 } | 1127 } |
1126 | 1128 |
1127 LoadDocument(); | 1129 LoadDocument(); |
(...skipping 22 matching lines...) Expand all Loading... | |
1150 } | 1152 } |
1151 | 1153 |
1152 void PDFiumEngine::OnNewDataAvailable() { | 1154 void PDFiumEngine::OnNewDataAvailable() { |
1153 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), | 1155 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), |
1154 doc_loader_.document_size()); | 1156 doc_loader_.document_size()); |
1155 } | 1157 } |
1156 | 1158 |
1157 void PDFiumEngine::OnDocumentComplete() { | 1159 void PDFiumEngine::OnDocumentComplete() { |
1158 if (!doc_ || !form_) { | 1160 if (!doc_ || !form_) { |
1159 file_access_.m_FileLen = doc_loader_.document_size(); | 1161 file_access_.m_FileLen = doc_loader_.document_size(); |
1162 if (!fpdf_availability_) { | |
1163 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); | |
1164 DCHECK(fpdf_availability_); | |
1165 } | |
1160 LoadDocument(); | 1166 LoadDocument(); |
1161 return; | 1167 return; |
1162 } | 1168 } |
1163 | 1169 |
1164 FinishLoadingDocument(); | 1170 FinishLoadingDocument(); |
1165 } | 1171 } |
1166 | 1172 |
1167 void PDFiumEngine::FinishLoadingDocument() { | 1173 void PDFiumEngine::FinishLoadingDocument() { |
1168 DCHECK(doc_loader_.IsDocumentComplete() && doc_); | 1174 DCHECK(doc_loader_.IsDocumentComplete() && doc_); |
1169 | 1175 |
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2494 bool* needs_password) { | 2500 bool* needs_password) { |
2495 *needs_password = false; | 2501 *needs_password = false; |
2496 if (doc_) | 2502 if (doc_) |
2497 return true; | 2503 return true; |
2498 | 2504 |
2499 const char* password_cstr = nullptr; | 2505 const char* password_cstr = nullptr; |
2500 if (with_password) { | 2506 if (with_password) { |
2501 password_cstr = password.c_str(); | 2507 password_cstr = password.c_str(); |
2502 password_tries_remaining_--; | 2508 password_tries_remaining_--; |
2503 } | 2509 } |
2504 if (doc_loader_.IsDocumentComplete()) | 2510 if (doc_loader_.IsDocumentComplete() && |
2511 !FPDFAvail_IsLinearized(fpdf_availability_)) { | |
2505 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); | 2512 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); |
2506 else | 2513 } else { |
2507 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); | 2514 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); |
2515 } | |
2508 | 2516 |
2509 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) | 2517 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) |
2510 *needs_password = true; | 2518 *needs_password = true; |
2511 | 2519 |
2512 return !!doc_; | 2520 return !!doc_; |
2513 } | 2521 } |
2514 | 2522 |
2515 void PDFiumEngine::GetPasswordAndLoad() { | 2523 void PDFiumEngine::GetPasswordAndLoad() { |
2516 getting_password_ = true; | 2524 getting_password_ = true; |
2517 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); | 2525 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3944 double* height) { | 3952 double* height) { |
3945 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3953 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3946 if (!doc) | 3954 if (!doc) |
3947 return false; | 3955 return false; |
3948 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3956 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3949 FPDF_CloseDocument(doc); | 3957 FPDF_CloseDocument(doc); |
3950 return success; | 3958 return success; |
3951 } | 3959 } |
3952 | 3960 |
3953 } // namespace chrome_pdf | 3961 } // namespace chrome_pdf |
OLD | NEW |