Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "gin/array_buffer.h" | 26 #include "gin/array_buffer.h" |
| 27 #include "gin/public/gin_embedders.h" | 27 #include "gin/public/gin_embedders.h" |
| 28 #include "gin/public/isolate_holder.h" | 28 #include "gin/public/isolate_holder.h" |
| 29 #include "pdf/draw_utils.h" | 29 #include "pdf/draw_utils.h" |
| 30 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" | 30 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" |
| 31 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h" | 31 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h" |
| 32 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h" | 32 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h" |
| 33 #include "pdf/url_loader_wrapper_impl.h" | |
| 33 #include "ppapi/c/pp_errors.h" | 34 #include "ppapi/c/pp_errors.h" |
| 34 #include "ppapi/c/pp_input_event.h" | 35 #include "ppapi/c/pp_input_event.h" |
| 35 #include "ppapi/c/ppb_core.h" | 36 #include "ppapi/c/ppb_core.h" |
| 36 #include "ppapi/c/private/ppb_pdf.h" | 37 #include "ppapi/c/private/ppb_pdf.h" |
| 37 #include "ppapi/cpp/dev/memory_dev.h" | 38 #include "ppapi/cpp/dev/memory_dev.h" |
| 38 #include "ppapi/cpp/input_event.h" | 39 #include "ppapi/cpp/input_event.h" |
| 39 #include "ppapi/cpp/instance.h" | 40 #include "ppapi/cpp/instance.h" |
| 40 #include "ppapi/cpp/module.h" | 41 #include "ppapi/cpp/module.h" |
| 41 #include "ppapi/cpp/private/pdf.h" | 42 #include "ppapi/cpp/private/pdf.h" |
| 42 #include "ppapi/cpp/trusted/browser_font_trusted.h" | 43 #include "ppapi/cpp/trusted/browser_font_trusted.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 } | 526 } |
| 526 | 527 |
| 527 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { | 528 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { |
| 528 return new PDFiumEngine(client); | 529 return new PDFiumEngine(client); |
| 529 } | 530 } |
| 530 | 531 |
| 531 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) | 532 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) |
| 532 : client_(client), | 533 : client_(client), |
| 533 current_zoom_(1.0), | 534 current_zoom_(1.0), |
| 534 current_rotation_(0), | 535 current_rotation_(0), |
| 535 doc_loader_(this), | |
| 536 password_tries_remaining_(0), | 536 password_tries_remaining_(0), |
| 537 doc_(nullptr), | 537 doc_(nullptr), |
| 538 form_(nullptr), | 538 form_(nullptr), |
| 539 defer_page_unload_(false), | 539 defer_page_unload_(false), |
| 540 selecting_(false), | 540 selecting_(false), |
| 541 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 541 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
| 542 PDFiumPage::LinkTarget()), | 542 PDFiumPage::LinkTarget()), |
| 543 next_page_to_search_(-1), | 543 next_page_to_search_(-1), |
| 544 last_page_to_search_(-1), | 544 last_page_to_search_(-1), |
| 545 last_character_index_to_search_(-1), | 545 last_character_index_to_search_(-1), |
| 546 permissions_(0), | 546 permissions_(0), |
| 547 permissions_handler_revision_(-1), | 547 permissions_handler_revision_(-1), |
| 548 fpdf_availability_(nullptr), | 548 fpdf_availability_(nullptr), |
| 549 next_timer_id_(0), | 549 next_timer_id_(0), |
| 550 last_page_mouse_down_(-1), | 550 last_page_mouse_down_(-1), |
| 551 most_visible_page_(-1), | 551 most_visible_page_(-1), |
| 552 called_do_document_action_(false), | 552 called_do_document_action_(false), |
| 553 render_grayscale_(false), | 553 render_grayscale_(false), |
| 554 render_annots_(true), | 554 render_annots_(true), |
| 555 progressive_paint_timeout_(0), | 555 progressive_paint_timeout_(0), |
| 556 getting_password_(false) { | 556 getting_password_(false) { |
| 557 find_factory_.Initialize(this); | 557 find_factory_.Initialize(this); |
| 558 password_factory_.Initialize(this); | 558 password_factory_.Initialize(this); |
| 559 | 559 |
| 560 file_access_.m_FileLen = 0; | 560 file_access_.m_FileLen = 0; |
| 561 file_access_.m_GetBlock = &GetBlock; | 561 file_access_.m_GetBlock = &GetBlock; |
| 562 file_access_.m_Param = &doc_loader_; | 562 file_access_.m_Param = this; |
| 563 | 563 |
| 564 file_availability_.version = 1; | 564 file_availability_.version = 1; |
| 565 file_availability_.IsDataAvail = &IsDataAvail; | 565 file_availability_.IsDataAvail = &IsDataAvail; |
| 566 file_availability_.loader = &doc_loader_; | 566 file_availability_.engine = this; |
| 567 | 567 |
| 568 download_hints_.version = 1; | 568 download_hints_.version = 1; |
| 569 download_hints_.AddSegment = &AddSegment; | 569 download_hints_.AddSegment = &AddSegment; |
| 570 download_hints_.loader = &doc_loader_; | 570 download_hints_.engine = this; |
| 571 | 571 |
| 572 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct | 572 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct |
| 573 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in | 573 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in |
| 574 // callbacks to ourself instead of maintaining a map of them to | 574 // callbacks to ourself instead of maintaining a map of them to |
| 575 // PDFiumEngine. | 575 // PDFiumEngine. |
| 576 FPDF_FORMFILLINFO::version = 1; | 576 FPDF_FORMFILLINFO::version = 1; |
| 577 FPDF_FORMFILLINFO::m_pJsPlatform = this; | 577 FPDF_FORMFILLINFO::m_pJsPlatform = this; |
| 578 FPDF_FORMFILLINFO::Release = nullptr; | 578 FPDF_FORMFILLINFO::Release = nullptr; |
| 579 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate; | 579 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate; |
| 580 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect; | 580 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, | 832 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, |
| 833 void* language, | 833 void* language, |
| 834 int length) { | 834 int length) { |
| 835 return 0; | 835 return 0; |
| 836 } | 836 } |
| 837 | 837 |
| 838 #endif // defined(PDF_ENABLE_XFA) | 838 #endif // defined(PDF_ENABLE_XFA) |
| 839 | 839 |
| 840 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 840 int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| 841 unsigned char* buffer, unsigned long size) { | 841 unsigned char* buffer, unsigned long size) { |
| 842 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 842 PDFiumEngine* p_this = static_cast<PDFiumEngine*>(param); |
|
Lei Zhang
2016/10/05 07:18:08
s/p_this/engine/ ?
snake
2016/10/05 14:14:10
Done.
| |
| 843 return loader->GetBlock(position, size, buffer); | 843 return p_this->doc_loader_->GetBlock(position, size, buffer); |
| 844 } | 844 } |
| 845 | 845 |
| 846 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 846 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 847 size_t offset, size_t size) { | 847 size_t offset, size_t size) { |
| 848 PDFiumEngine::FileAvail* file_avail = | 848 PDFiumEngine::FileAvail* file_avail = |
| 849 static_cast<PDFiumEngine::FileAvail*>(param); | 849 static_cast<PDFiumEngine::FileAvail*>(param); |
| 850 return file_avail->loader->IsDataAvailable(offset, size); | 850 return file_avail->engine->doc_loader_->IsDataAvailable(offset, size); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, | 853 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, |
| 854 size_t offset, size_t size) { | 854 size_t offset, size_t size) { |
| 855 PDFiumEngine::DownloadHints* download_hints = | 855 PDFiumEngine::DownloadHints* download_hints = |
| 856 static_cast<PDFiumEngine::DownloadHints*>(param); | 856 static_cast<PDFiumEngine::DownloadHints*>(param); |
| 857 return download_hints->loader->RequestData(offset, size); | 857 return download_hints->engine->doc_loader_->RequestData(offset, size); |
| 858 } | 858 } |
| 859 | 859 |
| 860 bool PDFiumEngine::New(const char* url, | 860 bool PDFiumEngine::New(const char* url, |
| 861 const char* headers) { | 861 const char* headers) { |
| 862 url_ = url; | 862 url_ = url; |
| 863 if (headers) | 863 if (headers) |
| 864 headers_ = headers; | 864 headers_ = headers; |
| 865 else | 865 else |
| 866 headers_.clear(); | 866 headers_.clear(); |
| 867 return true; | 867 return true; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 FPDF_RenderPage_Close( | 982 FPDF_RenderPage_Close( |
| 983 pages_[progressive_paints_[i].page_index]->GetPage()); | 983 pages_[progressive_paints_[i].page_index]->GetPage()); |
| 984 FPDFBitmap_Destroy(progressive_paints_[i].bitmap); | 984 FPDFBitmap_Destroy(progressive_paints_[i].bitmap); |
| 985 progressive_paints_.erase(progressive_paints_.begin() + i); | 985 progressive_paints_.erase(progressive_paints_.begin() + i); |
| 986 --i; | 986 --i; |
| 987 } | 987 } |
| 988 } | 988 } |
| 989 | 989 |
| 990 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { | 990 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { |
| 991 password_tries_remaining_ = kMaxPasswordTries; | 991 password_tries_remaining_ = kMaxPasswordTries; |
| 992 return doc_loader_.Init(loader, url_, headers_); | 992 should_process_pending_request_complete_ = true; |
| 993 URLLoaderWrapperImpl* loader_wrapper_ptr = | |
|
Lei Zhang
2016/10/05 07:18:07
Why bother with the raw pointer? Just:
auto loade
snake
2016/10/05 14:14:10
Done.
| |
| 994 new URLLoaderWrapperImpl(GetPluginInstance(), loader); | |
| 995 loader_wrapper_ptr->SetResponseHeaders(headers_); | |
| 996 std::unique_ptr<URLLoaderWrapper> loader_wrapper(loader_wrapper_ptr); | |
| 997 doc_loader_.reset(new DocumentLoader(this)); | |
|
Lei Zhang
2016/10/05 07:18:08
More base::MakeUnique?
snake
2016/10/05 14:14:10
Done.
| |
| 998 if (doc_loader_->Init(std::move(loader_wrapper), url_)) { | |
| 999 // request initial data. | |
| 1000 doc_loader_->RequestData(0, 1); | |
| 1001 return true; | |
| 1002 } | |
| 1003 return false; | |
| 993 } | 1004 } |
| 994 | 1005 |
| 995 pp::Instance* PDFiumEngine::GetPluginInstance() { | 1006 pp::Instance* PDFiumEngine::GetPluginInstance() { |
| 996 return client_->GetPluginInstance(); | 1007 return client_->GetPluginInstance(); |
| 997 } | 1008 } |
| 998 | 1009 |
| 999 pp::URLLoader PDFiumEngine::CreateURLLoader() { | 1010 std::unique_ptr<URLLoaderWrapper> PDFiumEngine::CreateURLLoader() { |
| 1000 return client_->CreateURLLoader(); | 1011 std::unique_ptr<URLLoaderWrapper> result; |
| 1012 result.reset(new URLLoaderWrapperImpl(GetPluginInstance(), | |
| 1013 client_->CreateURLLoader())); | |
| 1014 | |
| 1015 return result; | |
| 1001 } | 1016 } |
| 1002 | 1017 |
| 1003 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { | 1018 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { |
| 1004 // Unload and delete the blank page before appending. | 1019 // Unload and delete the blank page before appending. |
| 1005 pages_[index]->Unload(); | 1020 pages_[index]->Unload(); |
| 1006 pages_[index]->set_calculated_links(false); | 1021 pages_[index]->set_calculated_links(false); |
| 1007 pp::Size curr_page_size = GetPageSize(index); | 1022 pp::Size curr_page_size = GetPageSize(index); |
| 1008 FPDFPage_Delete(doc_, index); | 1023 FPDFPage_Delete(doc_, index); |
| 1009 FPDF_ImportPages(doc_, | 1024 FPDF_ImportPages(doc_, |
| 1010 static_cast<PDFiumEngine*>(engine)->doc(), | 1025 static_cast<PDFiumEngine*>(engine)->doc(), |
| 1011 "1", | 1026 "1", |
| 1012 index); | 1027 index); |
| 1013 pp::Size new_page_size = GetPageSize(index); | 1028 pp::Size new_page_size = GetPageSize(index); |
| 1014 if (curr_page_size != new_page_size) | 1029 if (curr_page_size != new_page_size) |
| 1015 LoadPageInfo(true); | 1030 LoadPageInfo(true); |
| 1016 client_->Invalidate(GetPageScreenRect(index)); | 1031 client_->Invalidate(GetPageScreenRect(index)); |
| 1017 } | 1032 } |
| 1018 | 1033 |
| 1019 #if defined(PDF_ENABLE_XFA) | 1034 #if defined(PDF_ENABLE_XFA) |
| 1020 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { | 1035 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { |
| 1021 position_ = position; | 1036 position_ = position; |
| 1022 } | 1037 } |
| 1023 #endif | 1038 #endif |
| 1024 | 1039 |
| 1025 bool PDFiumEngine::IsProgressiveLoad() { | |
| 1026 return doc_loader_.is_partial_document(); | |
| 1027 } | |
| 1028 | |
| 1029 std::string PDFiumEngine::GetMetadata(const std::string& key) { | 1040 std::string PDFiumEngine::GetMetadata(const std::string& key) { |
| 1030 return GetDocumentMetadata(doc(), key); | 1041 return GetDocumentMetadata(doc(), key); |
| 1031 } | 1042 } |
| 1032 | 1043 |
| 1033 void PDFiumEngine::OnPartialDocumentLoaded() { | 1044 void PDFiumEngine::OnPendingRequestComplete() { |
| 1034 file_access_.m_FileLen = doc_loader_.document_size(); | 1045 if (!should_process_pending_request_complete_) |
| 1046 return; | |
| 1035 if (!fpdf_availability_) { | 1047 if (!fpdf_availability_) { |
| 1048 file_access_.m_FileLen = doc_loader_->GetDocumentSize(); | |
| 1036 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); | 1049 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
| 1037 DCHECK(fpdf_availability_); | 1050 DCHECK(fpdf_availability_); |
| 1051 // Currently engine does not deal efficiently with some non-linearized | |
| 1052 // files. | |
| 1053 // See http://code.google.com/p/chromium/issues/detail?id=59400 | |
| 1054 // To improve user experience we download entire file for non-linearized | |
| 1055 // PDF. | |
| 1056 if (FPDFAvail_IsLinearized(fpdf_availability_) != PDF_LINEARIZED) { | |
| 1057 // Wait complete document. | |
| 1058 should_process_pending_request_complete_ = false; | |
| 1059 FPDFAvail_Destroy(fpdf_availability_); | |
| 1060 fpdf_availability_ = nullptr; | |
| 1061 return; | |
| 1062 } | |
| 1038 } | 1063 } |
| 1039 | 1064 |
| 1040 // Currently engine does not deal efficiently with some non-linearized files. | 1065 if (!doc_) { |
| 1041 // See http://code.google.com/p/chromium/issues/detail?id=59400 | |
| 1042 // To improve user experience we download entire file for non-linearized PDF. | |
| 1043 if (!FPDFAvail_IsLinearized(fpdf_availability_)) { | |
| 1044 doc_loader_.RequestData(0, doc_loader_.document_size()); | |
| 1045 return; | |
| 1046 } | |
| 1047 | |
| 1048 LoadDocument(); | |
| 1049 } | |
| 1050 | |
| 1051 void PDFiumEngine::OnPendingRequestComplete() { | |
| 1052 if (!doc_ || !form_) { | |
| 1053 DCHECK(fpdf_availability_); | |
| 1054 LoadDocument(); | 1066 LoadDocument(); |
| 1055 return; | 1067 return; |
| 1056 } | 1068 } |
| 1057 | 1069 |
| 1058 // LoadDocument() will result in |pending_pages_| being reset so there's no | 1070 // LoadDocument() will result in |pending_pages_| being reset so there's no |
| 1059 // need to run the code below in that case. | 1071 // need to run the code below in that case. |
| 1060 bool update_pages = false; | 1072 bool update_pages = false; |
| 1061 std::vector<int> still_pending; | 1073 std::vector<int> still_pending; |
| 1062 for (int pending_page : pending_pages_) { | 1074 for (int pending_page : pending_pages_) { |
| 1063 if (CheckPageAvailable(pending_page, &still_pending)) { | 1075 if (CheckPageAvailable(pending_page, &still_pending)) { |
| 1064 update_pages = true; | 1076 update_pages = true; |
| 1065 if (IsPageVisible(pending_page)) | 1077 if (IsPageVisible(pending_page)) |
| 1066 client_->Invalidate(GetPageScreenRect(pending_page)); | 1078 client_->Invalidate(GetPageScreenRect(pending_page)); |
| 1067 } | 1079 } |
| 1068 } | 1080 } |
| 1069 pending_pages_.swap(still_pending); | 1081 pending_pages_.swap(still_pending); |
| 1070 if (update_pages) | 1082 if (update_pages) |
| 1071 LoadPageInfo(true); | 1083 LoadPageInfo(true); |
| 1072 } | 1084 } |
| 1073 | 1085 |
| 1074 void PDFiumEngine::OnNewDataAvailable() { | 1086 void PDFiumEngine::OnNewDataAvailable() { |
| 1075 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), | 1087 const float progress = doc_loader_->GetProgress(); |
| 1076 doc_loader_.document_size()); | 1088 if (progress < 0.001) { |
| 1089 client_->DocumentLoadProgress(0, 0); | |
| 1090 } else { | |
| 1091 client_->DocumentLoadProgress(progress * 10000, 10000); | |
| 1092 } | |
| 1077 } | 1093 } |
| 1078 | 1094 |
| 1079 void PDFiumEngine::OnDocumentComplete() { | 1095 void PDFiumEngine::OnDocumentComplete() { |
| 1080 if (!doc_ || !form_) { | 1096 if (!doc_) { |
|
Lei Zhang
2016/10/05 07:18:08
In general, if (!foo) { bar(); } else { qux(); } m
snake
2016/10/05 14:14:10
Done.
| |
| 1081 file_access_.m_FileLen = doc_loader_.document_size(); | 1097 file_access_.m_FileLen = doc_loader_->GetDocumentSize(); |
| 1082 if (!fpdf_availability_) { | 1098 if (!fpdf_availability_) { |
| 1083 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); | 1099 fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
| 1084 DCHECK(fpdf_availability_); | 1100 DCHECK(fpdf_availability_); |
| 1085 } | 1101 } |
| 1086 LoadDocument(); | 1102 LoadDocument(); |
| 1087 return; | 1103 } else { |
| 1104 FinishLoadingDocument(); | |
|
Lei Zhang
2016/10/05 07:18:07
Or how about just:
if (doc_) {
FinishLoadingDoc
snake
2016/10/05 14:14:10
Done.
| |
| 1088 } | 1105 } |
| 1106 } | |
| 1089 | 1107 |
| 1090 FinishLoadingDocument(); | 1108 void PDFiumEngine::OnDocumentCanceled() { |
| 1109 OnDocumentComplete(); | |
| 1110 } | |
| 1111 | |
| 1112 void PDFiumEngine::CancelBrowserDownload() { | |
| 1113 client_->CancelBrowserDownload(); | |
| 1091 } | 1114 } |
| 1092 | 1115 |
| 1093 void PDFiumEngine::FinishLoadingDocument() { | 1116 void PDFiumEngine::FinishLoadingDocument() { |
| 1094 DCHECK(doc_loader_.IsDocumentComplete() && doc_); | 1117 DCHECK(doc_loader_->IsDocumentComplete() && doc_); |
| 1118 | |
| 1119 if (!form_) { | |
| 1120 int form_status = | |
| 1121 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_); | |
| 1122 if (form_status != PDF_FORM_NOTAVAIL) { | |
| 1123 form_ = FPDFDOC_InitFormFillEnvironment( | |
| 1124 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); | |
| 1125 #if defined(PDF_ENABLE_XFA) | |
| 1126 FPDF_LoadXFA(doc_); | |
| 1127 #endif | |
| 1128 | |
| 1129 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); | |
| 1130 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); | |
| 1131 } | |
| 1132 } | |
| 1095 | 1133 |
| 1096 bool need_update = false; | 1134 bool need_update = false; |
| 1097 for (size_t i = 0; i < pages_.size(); ++i) { | 1135 for (size_t i = 0; i < pages_.size(); ++i) { |
| 1098 if (pages_[i]->available()) | 1136 if (pages_[i]->available()) |
| 1099 continue; | 1137 continue; |
| 1100 | 1138 |
| 1101 pages_[i]->set_available(true); | 1139 pages_[i]->set_available(true); |
| 1102 // We still need to call IsPageAvail() even if the whole document is | 1140 // We still need to call IsPageAvail() even if the whole document is |
| 1103 // already downloaded. | 1141 // already downloaded. |
| 1104 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); | 1142 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 return temp_doc; | 1329 return temp_doc; |
| 1292 } | 1330 } |
| 1293 | 1331 |
| 1294 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( | 1332 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( |
| 1295 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, | 1333 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, |
| 1296 const PP_PrintSettings_Dev& print_settings) { | 1334 const PP_PrintSettings_Dev& print_settings) { |
| 1297 if (!page_range_count) | 1335 if (!page_range_count) |
| 1298 return pp::Buffer_Dev(); | 1336 return pp::Buffer_Dev(); |
| 1299 | 1337 |
| 1300 // If document is not downloaded yet, disable printing. | 1338 // If document is not downloaded yet, disable printing. |
| 1301 if (doc_ && !doc_loader_.IsDocumentComplete()) | 1339 if (doc_ && !doc_loader_->IsDocumentComplete()) |
| 1302 return pp::Buffer_Dev(); | 1340 return pp::Buffer_Dev(); |
| 1303 | 1341 |
| 1304 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); | 1342 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); |
| 1305 if (!output_doc) | 1343 if (!output_doc) |
| 1306 return pp::Buffer_Dev(); | 1344 return pp::Buffer_Dev(); |
| 1307 | 1345 |
| 1308 SaveSelectedFormForPrint(); | 1346 SaveSelectedFormForPrint(); |
| 1309 | 1347 |
| 1310 std::vector<PDFiumPage> pages_to_print; | 1348 std::vector<PDFiumPage> pages_to_print; |
| 1311 // width and height of source PDF pages. | 1349 // width and height of source PDF pages. |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2429 } | 2467 } |
| 2430 | 2468 |
| 2431 CalculateVisiblePages(); | 2469 CalculateVisiblePages(); |
| 2432 if (document_size_ != old_document_size) | 2470 if (document_size_ != old_document_size) |
| 2433 client_->DocumentSizeUpdated(document_size_); | 2471 client_->DocumentSizeUpdated(document_size_); |
| 2434 } | 2472 } |
| 2435 | 2473 |
| 2436 void PDFiumEngine::LoadDocument() { | 2474 void PDFiumEngine::LoadDocument() { |
| 2437 // Check if the document is ready for loading. If it isn't just bail for now, | 2475 // Check if the document is ready for loading. If it isn't just bail for now, |
| 2438 // we will call LoadDocument() again later. | 2476 // we will call LoadDocument() again later. |
| 2439 if (!doc_ && !doc_loader_.IsDocumentComplete() && | 2477 if (!doc_ && !doc_loader_->IsDocumentComplete() && |
| 2440 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) { | 2478 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) { |
| 2441 return; | 2479 return; |
| 2442 } | 2480 } |
| 2443 | 2481 |
| 2444 // If we're in the middle of getting a password, just return. We will retry | 2482 // If we're in the middle of getting a password, just return. We will retry |
| 2445 // loading the document after we get the password anyway. | 2483 // loading the document after we get the password anyway. |
| 2446 if (getting_password_) | 2484 if (getting_password_) |
| 2447 return; | 2485 return; |
| 2448 | 2486 |
| 2449 ScopedUnsupportedFeature scoped_unsupported_feature(this); | 2487 ScopedUnsupportedFeature scoped_unsupported_feature(this); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2467 // call may have failed, so call it again for good measure. | 2505 // call may have failed, so call it again for good measure. |
| 2468 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_); | 2506 FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_); |
| 2469 return true; | 2507 return true; |
| 2470 } | 2508 } |
| 2471 | 2509 |
| 2472 const char* password_cstr = nullptr; | 2510 const char* password_cstr = nullptr; |
| 2473 if (!password.empty()) { | 2511 if (!password.empty()) { |
| 2474 password_cstr = password.c_str(); | 2512 password_cstr = password.c_str(); |
| 2475 password_tries_remaining_--; | 2513 password_tries_remaining_--; |
| 2476 } | 2514 } |
| 2477 if (doc_loader_.IsDocumentComplete() && | 2515 if (doc_loader_->IsDocumentComplete() && |
| 2478 !FPDFAvail_IsLinearized(fpdf_availability_)) { | 2516 !FPDFAvail_IsLinearized(fpdf_availability_)) { |
| 2479 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); | 2517 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); |
| 2480 } else { | 2518 } else { |
| 2481 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); | 2519 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); |
| 2482 } | 2520 } |
| 2483 if (!doc_) { | 2521 if (!doc_) { |
| 2484 if (FPDF_GetLastError() == FPDF_ERR_PASSWORD) | 2522 if (FPDF_GetLastError() == FPDF_ERR_PASSWORD) |
| 2485 *needs_password = true; | 2523 *needs_password = true; |
| 2486 return false; | 2524 return false; |
| 2487 } | 2525 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2524 client_->DocumentLoadFailed(); | 2562 client_->DocumentLoadFailed(); |
| 2525 return; | 2563 return; |
| 2526 } | 2564 } |
| 2527 | 2565 |
| 2528 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES) | 2566 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES) |
| 2529 client_->DocumentHasUnsupportedFeature("Bookmarks"); | 2567 client_->DocumentHasUnsupportedFeature("Bookmarks"); |
| 2530 | 2568 |
| 2531 permissions_ = FPDF_GetDocPermissions(doc_); | 2569 permissions_ = FPDF_GetDocPermissions(doc_); |
| 2532 permissions_handler_revision_ = FPDF_GetSecurityHandlerRevision(doc_); | 2570 permissions_handler_revision_ = FPDF_GetSecurityHandlerRevision(doc_); |
| 2533 | 2571 |
| 2534 if (!form_) { | 2572 if (!doc_loader_->IsDocumentComplete()) { |
| 2535 int form_status = | |
| 2536 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_); | |
| 2537 bool doc_complete = doc_loader_.IsDocumentComplete(); | |
| 2538 // Try again if the data is not available and the document hasn't finished | |
| 2539 // downloading. | |
| 2540 if (form_status == PDF_FORM_NOTAVAIL && !doc_complete) | |
| 2541 return; | |
| 2542 | |
| 2543 form_ = FPDFDOC_InitFormFillEnvironment( | |
| 2544 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); | |
| 2545 #if defined(PDF_ENABLE_XFA) | |
| 2546 FPDF_LoadXFA(doc_); | |
| 2547 #endif | |
| 2548 | |
| 2549 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); | |
| 2550 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); | |
| 2551 } | |
| 2552 | |
| 2553 if (!doc_loader_.IsDocumentComplete()) { | |
| 2554 // Check if the first page is available. In a linearized PDF, that is not | 2573 // Check if the first page is available. In a linearized PDF, that is not |
| 2555 // always page 0. Doing this gives us the default page size, since when the | 2574 // always page 0. Doing this gives us the default page size, since when the |
| 2556 // document is available, the first page is available as well. | 2575 // document is available, the first page is available as well. |
| 2557 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); | 2576 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); |
| 2558 } | 2577 } |
| 2559 | 2578 |
| 2560 LoadPageInfo(false); | 2579 LoadPageInfo(false); |
| 2561 | 2580 |
| 2562 if (doc_loader_.IsDocumentComplete()) | 2581 if (doc_loader_->IsDocumentComplete()) |
| 2563 FinishLoadingDocument(); | 2582 FinishLoadingDocument(); |
| 2564 } | 2583 } |
| 2565 | 2584 |
| 2566 void PDFiumEngine::LoadPageInfo(bool reload) { | 2585 void PDFiumEngine::LoadPageInfo(bool reload) { |
| 2567 pending_pages_.clear(); | 2586 pending_pages_.clear(); |
| 2568 pp::Size old_document_size = document_size_; | 2587 pp::Size old_document_size = document_size_; |
| 2569 document_size_ = pp::Size(); | 2588 document_size_ = pp::Size(); |
| 2570 std::vector<pp::Rect> page_rects; | 2589 std::vector<pp::Rect> page_rects; |
| 2571 int page_count = FPDF_GetPageCount(doc_); | 2590 int page_count = FPDF_GetPageCount(doc_); |
| 2572 bool doc_complete = doc_loader_.IsDocumentComplete(); | 2591 bool doc_complete = doc_loader_->IsDocumentComplete(); |
| 2573 bool is_linear = FPDFAvail_IsLinearized(fpdf_availability_) == PDF_LINEARIZED; | 2592 bool is_linear = FPDFAvail_IsLinearized(fpdf_availability_) == PDF_LINEARIZED; |
| 2574 for (int i = 0; i < page_count; ++i) { | 2593 for (int i = 0; i < page_count; ++i) { |
| 2575 if (i != 0) { | 2594 if (i != 0) { |
| 2576 // Add space for horizontal separator. | 2595 // Add space for horizontal separator. |
| 2577 document_size_.Enlarge(0, kPageSeparatorThickness); | 2596 document_size_.Enlarge(0, kPageSeparatorThickness); |
| 2578 } | 2597 } |
| 2579 | 2598 |
| 2580 // Get page availability. If |reload| == true, then the document has been | 2599 // Get page availability. If |reload| == true, then the document has been |
| 2581 // constructed already. Get page availability flag from already existing | 2600 // constructed already. Get page availability flag from already existing |
| 2582 // PDFiumPage class. | 2601 // PDFiumPage class. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2619 pages_.push_back(new PDFiumPage(this, i, page_rect, false)); | 2638 pages_.push_back(new PDFiumPage(this, i, page_rect, false)); |
| 2620 } | 2639 } |
| 2621 } | 2640 } |
| 2622 | 2641 |
| 2623 CalculateVisiblePages(); | 2642 CalculateVisiblePages(); |
| 2624 if (document_size_ != old_document_size) | 2643 if (document_size_ != old_document_size) |
| 2625 client_->DocumentSizeUpdated(document_size_); | 2644 client_->DocumentSizeUpdated(document_size_); |
| 2626 } | 2645 } |
| 2627 | 2646 |
| 2628 void PDFiumEngine::CalculateVisiblePages() { | 2647 void PDFiumEngine::CalculateVisiblePages() { |
| 2648 if (!doc_loader_) | |
| 2649 return; | |
| 2629 // Clear pending requests queue, since it may contain requests to the pages | 2650 // Clear pending requests queue, since it may contain requests to the pages |
| 2630 // that are already invisible (after scrolling for example). | 2651 // that are already invisible (after scrolling for example). |
| 2631 pending_pages_.clear(); | 2652 pending_pages_.clear(); |
| 2632 doc_loader_.ClearPendingRequests(); | 2653 doc_loader_->ClearPendingRequests(); |
| 2633 | 2654 |
| 2634 visible_pages_.clear(); | 2655 visible_pages_.clear(); |
| 2635 pp::Rect visible_rect(plugin_size_); | 2656 pp::Rect visible_rect(plugin_size_); |
| 2636 for (size_t i = 0; i < pages_.size(); ++i) { | 2657 for (size_t i = 0; i < pages_.size(); ++i) { |
| 2637 // Check an entire PageScreenRect, since we might need to repaint side | 2658 // Check an entire PageScreenRect, since we might need to repaint side |
| 2638 // borders and shadows even if the page itself is not visible. | 2659 // borders and shadows even if the page itself is not visible. |
| 2639 // For example, when user use pdf with different page sizes and zoomed in | 2660 // For example, when user use pdf with different page sizes and zoomed in |
| 2640 // outside page area. | 2661 // outside page area. |
| 2641 if (visible_rect.Intersects(GetPageScreenRect(i))) { | 2662 if (visible_rect.Intersects(GetPageScreenRect(i))) { |
| 2642 visible_pages_.push_back(i); | 2663 visible_pages_.push_back(i); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2680 bool PDFiumEngine::IsPageVisible(int index) const { | 2701 bool PDFiumEngine::IsPageVisible(int index) const { |
| 2681 return base::ContainsValue(visible_pages_, index); | 2702 return base::ContainsValue(visible_pages_, index); |
| 2682 } | 2703 } |
| 2683 | 2704 |
| 2684 void PDFiumEngine::ScrollToPage(int page) { | 2705 void PDFiumEngine::ScrollToPage(int page) { |
| 2685 in_flight_visible_page_ = page; | 2706 in_flight_visible_page_ = page; |
| 2686 client_->ScrollToPage(page); | 2707 client_->ScrollToPage(page); |
| 2687 } | 2708 } |
| 2688 | 2709 |
| 2689 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { | 2710 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { |
| 2690 if (!doc_ || !form_) | 2711 if (!doc_) |
| 2691 return false; | 2712 return false; |
| 2692 | 2713 |
| 2693 const int num_pages = static_cast<int>(pages_.size()); | 2714 const int num_pages = static_cast<int>(pages_.size()); |
| 2694 if (index < num_pages && pages_[index]->available()) | 2715 if (index < num_pages && pages_[index]->available()) |
| 2695 return true; | 2716 return true; |
| 2696 | 2717 |
| 2697 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { | 2718 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { |
| 2698 if (!base::ContainsValue(*pending, index)) | 2719 if (!base::ContainsValue(*pending, index)) |
| 2699 pending->push_back(index); | 2720 pending->push_back(index); |
| 2700 return false; | 2721 return false; |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3975 FPDF_DOCUMENT doc = | 3996 FPDF_DOCUMENT doc = |
| 3976 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 3997 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 3977 if (!doc) | 3998 if (!doc) |
| 3978 return false; | 3999 return false; |
| 3979 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4000 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3980 FPDF_CloseDocument(doc); | 4001 FPDF_CloseDocument(doc); |
| 3981 return success; | 4002 return success; |
| 3982 } | 4003 } |
| 3983 | 4004 |
| 3984 } // namespace chrome_pdf | 4005 } // namespace chrome_pdf |
| OLD | NEW |