| 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 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); | 604 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| 605 FPDFDOC_ExitFormFillEnviroument(form_); | 605 FPDFDOC_ExitFormFillEnviroument(form_); |
| 606 } | 606 } |
| 607 FPDF_CloseDocument(doc_); | 607 FPDF_CloseDocument(doc_); |
| 608 } | 608 } |
| 609 | 609 |
| 610 if (fpdf_availability_) | 610 if (fpdf_availability_) |
| 611 FPDFAvail_Destroy(fpdf_availability_); | 611 FPDFAvail_Destroy(fpdf_availability_); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void PDFiumEngine::ClientDestroyed() { |
| 615 client_ = NULL; |
| 616 } |
| 617 |
| 614 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 618 int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| 615 unsigned char* buffer, unsigned long size) { | 619 unsigned char* buffer, unsigned long size) { |
| 616 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 620 DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| 617 return loader->GetBlock(position, size, buffer); | 621 return loader->GetBlock(position, size, buffer); |
| 618 } | 622 } |
| 619 | 623 |
| 620 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 624 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 621 size_t offset, size_t size) { | 625 size_t offset, size_t size) { |
| 622 PDFiumEngine::FileAvail* file_avail = | 626 PDFiumEngine::FileAvail* file_avail = |
| 623 static_cast<PDFiumEngine::FileAvail*>(param); | 627 static_cast<PDFiumEngine::FileAvail*>(param); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 653 | 657 |
| 654 void PDFiumEngine::PluginSizeUpdated(const pp::Size& size) { | 658 void PDFiumEngine::PluginSizeUpdated(const pp::Size& size) { |
| 655 CancelPaints(); | 659 CancelPaints(); |
| 656 | 660 |
| 657 plugin_size_ = size; | 661 plugin_size_ = size; |
| 658 CalculateVisiblePages(); | 662 CalculateVisiblePages(); |
| 659 } | 663 } |
| 660 | 664 |
| 661 void PDFiumEngine::ScrolledToXPosition(int position) { | 665 void PDFiumEngine::ScrolledToXPosition(int position) { |
| 662 CancelPaints(); | 666 CancelPaints(); |
| 667 if (!client_) |
| 668 return; |
| 663 | 669 |
| 664 int old_x = position_.x(); | 670 int old_x = position_.x(); |
| 665 position_.set_x(position); | 671 position_.set_x(position); |
| 666 CalculateVisiblePages(); | 672 CalculateVisiblePages(); |
| 667 client_->Scroll(pp::Point(old_x - position, 0)); | 673 client_->Scroll(pp::Point(old_x - position, 0)); |
| 668 } | 674 } |
| 669 | 675 |
| 670 void PDFiumEngine::ScrolledToYPosition(int position) { | 676 void PDFiumEngine::ScrolledToYPosition(int position) { |
| 671 CancelPaints(); | 677 CancelPaints(); |
| 678 if (!client_) |
| 679 return; |
| 672 | 680 |
| 673 int old_y = position_.y(); | 681 int old_y = position_.y(); |
| 674 position_.set_y(position); | 682 position_.set_y(position); |
| 675 CalculateVisiblePages(); | 683 CalculateVisiblePages(); |
| 676 client_->Scroll(pp::Point(0, old_y - position)); | 684 client_->Scroll(pp::Point(0, old_y - position)); |
| 677 } | 685 } |
| 678 | 686 |
| 679 void PDFiumEngine::PrePaint() { | 687 void PDFiumEngine::PrePaint() { |
| 680 for (size_t i = 0; i < progressive_paints_.size(); ++i) | 688 for (size_t i = 0; i < progressive_paints_.size(); ++i) |
| 681 progressive_paints_[i].painted_ = false; | 689 progressive_paints_[i].painted_ = false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 --i; | 758 --i; |
| 751 } | 759 } |
| 752 } | 760 } |
| 753 | 761 |
| 754 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { | 762 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { |
| 755 password_tries_remaining_ = kMaxPasswordTries; | 763 password_tries_remaining_ = kMaxPasswordTries; |
| 756 return doc_loader_.Init(loader, url_, headers_); | 764 return doc_loader_.Init(loader, url_, headers_); |
| 757 } | 765 } |
| 758 | 766 |
| 759 pp::Instance* PDFiumEngine::GetPluginInstance() { | 767 pp::Instance* PDFiumEngine::GetPluginInstance() { |
| 760 return client_->GetPluginInstance(); | 768 return client_ ? client_->GetPluginInstance() : NULL; |
| 761 } | 769 } |
| 762 | 770 |
| 763 pp::URLLoader PDFiumEngine::CreateURLLoader() { | 771 pp::URLLoader PDFiumEngine::CreateURLLoader() { |
| 764 return client_->CreateURLLoader(); | 772 return client_ ? client_->CreateURLLoader() : pp::URLLoader(); |
| 765 } | 773 } |
| 766 | 774 |
| 767 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { | 775 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { |
| 768 // Unload and delete the blank page before appending. | 776 // Unload and delete the blank page before appending. |
| 769 pages_[index]->Unload(); | 777 pages_[index]->Unload(); |
| 770 pages_[index]->set_calculated_links(false); | 778 pages_[index]->set_calculated_links(false); |
| 771 pp::Size curr_page_size = GetPageSize(index); | 779 pp::Size curr_page_size = GetPageSize(index); |
| 772 FPDFPage_Delete(doc_, index); | 780 FPDFPage_Delete(doc_, index); |
| 773 FPDF_ImportPages(doc_, | 781 FPDF_ImportPages(doc_, |
| 774 static_cast<PDFiumEngine*>(engine)->doc(), | 782 static_cast<PDFiumEngine*>(engine)->doc(), |
| 775 "1", | 783 "1", |
| 776 index); | 784 index); |
| 777 pp::Size new_page_size = GetPageSize(index); | 785 pp::Size new_page_size = GetPageSize(index); |
| 778 if (curr_page_size != new_page_size) | 786 if (curr_page_size != new_page_size) |
| 779 LoadPageInfo(true); | 787 LoadPageInfo(true); |
| 788 if (!client_) |
| 789 return; |
| 790 |
| 780 client_->Invalidate(GetPageScreenRect(index)); | 791 client_->Invalidate(GetPageScreenRect(index)); |
| 781 } | 792 } |
| 782 | 793 |
| 783 pp::Point PDFiumEngine::GetScrollPosition() { | 794 pp::Point PDFiumEngine::GetScrollPosition() { |
| 784 return position_; | 795 return position_; |
| 785 } | 796 } |
| 786 | 797 |
| 787 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { | 798 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { |
| 788 position_ = position; | 799 position_ = position; |
| 789 } | 800 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 814 return; | 825 return; |
| 815 } | 826 } |
| 816 | 827 |
| 817 // LoadDocument() will result in |pending_pages_| being reset so there's no | 828 // LoadDocument() will result in |pending_pages_| being reset so there's no |
| 818 // need to run the code below in that case. | 829 // need to run the code below in that case. |
| 819 bool update_pages = false; | 830 bool update_pages = false; |
| 820 std::vector<int> still_pending; | 831 std::vector<int> still_pending; |
| 821 for (size_t i = 0; i < pending_pages_.size(); ++i) { | 832 for (size_t i = 0; i < pending_pages_.size(); ++i) { |
| 822 if (CheckPageAvailable(pending_pages_[i], &still_pending)) { | 833 if (CheckPageAvailable(pending_pages_[i], &still_pending)) { |
| 823 update_pages = true; | 834 update_pages = true; |
| 824 if (IsPageVisible(pending_pages_[i])) | 835 if (client_ && IsPageVisible(pending_pages_[i])) |
| 825 client_->Invalidate(GetPageScreenRect(pending_pages_[i])); | 836 client_->Invalidate(GetPageScreenRect(pending_pages_[i])); |
| 826 } | 837 } |
| 827 } | 838 } |
| 828 pending_pages_.swap(still_pending); | 839 pending_pages_.swap(still_pending); |
| 829 if (update_pages) | 840 if (update_pages) |
| 830 LoadPageInfo(true); | 841 LoadPageInfo(true); |
| 831 } | 842 } |
| 832 | 843 |
| 833 void PDFiumEngine::OnNewDataAvailable() { | 844 void PDFiumEngine::OnNewDataAvailable() { |
| 845 if (!client_) |
| 846 return; |
| 834 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), | 847 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), |
| 835 doc_loader_.document_size()); | 848 doc_loader_.document_size()); |
| 836 } | 849 } |
| 837 | 850 |
| 838 void PDFiumEngine::OnDocumentComplete() { | 851 void PDFiumEngine::OnDocumentComplete() { |
| 839 if (!doc_ || !form_) { | 852 if (!doc_ || !form_) { |
| 840 file_access_.m_FileLen = doc_loader_.document_size(); | 853 file_access_.m_FileLen = doc_loader_.document_size(); |
| 841 LoadDocument(); | 854 LoadDocument(); |
| 842 return; | 855 return; |
| 843 } | 856 } |
| 844 | 857 |
| 845 bool need_update = false; | 858 bool need_update = false; |
| 846 for (size_t i = 0; i < pages_.size(); ++i) { | 859 for (size_t i = 0; i < pages_.size(); ++i) { |
| 847 if (pages_[i]->available()) | 860 if (pages_[i]->available()) |
| 848 continue; | 861 continue; |
| 849 | 862 |
| 850 pages_[i]->set_available(true); | 863 pages_[i]->set_available(true); |
| 851 // We still need to call IsPageAvail() even if the whole document is | 864 // We still need to call IsPageAvail() even if the whole document is |
| 852 // already downloaded. | 865 // already downloaded. |
| 853 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); | 866 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); |
| 854 need_update = true; | 867 need_update = true; |
| 855 if (IsPageVisible(i)) | 868 if (client_ && IsPageVisible(i)) |
| 856 client_->Invalidate(GetPageScreenRect(i)); | 869 client_->Invalidate(GetPageScreenRect(i)); |
| 857 } | 870 } |
| 858 if (need_update) | 871 if (need_update) |
| 859 LoadPageInfo(true); | 872 LoadPageInfo(true); |
| 860 | 873 |
| 861 FinishLoadingDocument(); | 874 FinishLoadingDocument(); |
| 862 } | 875 } |
| 863 | 876 |
| 864 void PDFiumEngine::FinishLoadingDocument() { | 877 void PDFiumEngine::FinishLoadingDocument() { |
| 865 DCHECK(doc_loader_.IsDocumentComplete() && doc_); | 878 DCHECK(doc_loader_.IsDocumentComplete() && doc_); |
| 866 if (called_do_document_action_) | 879 if (called_do_document_action_) |
| 867 return; | 880 return; |
| 868 called_do_document_action_ = true; | 881 called_do_document_action_ = true; |
| 869 | 882 |
| 870 // These can only be called now, as the JS might end up needing a page. | 883 // These can only be called now, as the JS might end up needing a page. |
| 871 FORM_DoDocumentJSAction(form_); | 884 FORM_DoDocumentJSAction(form_); |
| 872 FORM_DoDocumentOpenAction(form_); | 885 FORM_DoDocumentOpenAction(form_); |
| 873 if (most_visible_page_ != -1) { | 886 if (most_visible_page_ != -1) { |
| 874 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); | 887 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); |
| 875 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); | 888 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); |
| 876 } | 889 } |
| 877 | 890 |
| 878 if (doc_) // This can only happen if loading |doc_| fails. | 891 if (doc_ && client_) // This can only happen if loading |doc_| fails. |
| 879 client_->DocumentLoadComplete(pages_.size()); | 892 client_->DocumentLoadComplete(pages_.size()); |
| 880 } | 893 } |
| 881 | 894 |
| 882 void PDFiumEngine::UnsupportedFeature(int type) { | 895 void PDFiumEngine::UnsupportedFeature(int type) { |
| 896 if (!client_) |
| 897 return; |
| 898 |
| 883 std::string feature; | 899 std::string feature; |
| 884 switch (type) { | 900 switch (type) { |
| 885 case FPDF_UNSP_DOC_XFAFORM: | 901 case FPDF_UNSP_DOC_XFAFORM: |
| 886 feature = "XFA"; | 902 feature = "XFA"; |
| 887 break; | 903 break; |
| 888 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 904 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 889 feature = "Portfolios_Packages"; | 905 feature = "Portfolios_Packages"; |
| 890 break; | 906 break; |
| 891 case FPDF_UNSP_DOC_ATTACHMENT: | 907 case FPDF_UNSP_DOC_ATTACHMENT: |
| 892 case FPDF_UNSP_ANNOT_ATTACHMENT: | 908 case FPDF_UNSP_ANNOT_ATTACHMENT: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) | 994 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) |
| 979 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); | 995 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); |
| 980 else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) | 996 else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) |
| 981 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); | 997 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); |
| 982 return pp::Resource(); | 998 return pp::Resource(); |
| 983 } | 999 } |
| 984 | 1000 |
| 985 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( | 1001 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( |
| 986 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, | 1002 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, |
| 987 const PP_PrintSettings_Dev& print_settings) { | 1003 const PP_PrintSettings_Dev& print_settings) { |
| 1004 if (!client_) |
| 1005 return pp::Buffer_Dev(); |
| 1006 |
| 988 if (!page_range_count) | 1007 if (!page_range_count) |
| 989 return pp::Buffer_Dev(); | 1008 return pp::Buffer_Dev(); |
| 990 | 1009 |
| 991 // If document is not downloaded yet, disable printing. | 1010 // If document is not downloaded yet, disable printing. |
| 992 if (doc_ && !doc_loader_.IsDocumentComplete()) | 1011 if (doc_ && !doc_loader_.IsDocumentComplete()) |
| 993 return pp::Buffer_Dev(); | 1012 return pp::Buffer_Dev(); |
| 994 | 1013 |
| 995 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); | 1014 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); |
| 996 if (!output_doc) | 1015 if (!output_doc) |
| 997 return pp::Buffer_Dev(); | 1016 return pp::Buffer_Dev(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 FPDF_CopyViewerPreferences(output_doc, doc_); | 1119 FPDF_CopyViewerPreferences(output_doc, doc_); |
| 1101 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1120 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
| 1102 // Now flatten all the output pages. | 1121 // Now flatten all the output pages. |
| 1103 buffer = GetFlattenedPrintData(output_doc); | 1122 buffer = GetFlattenedPrintData(output_doc); |
| 1104 } | 1123 } |
| 1105 FPDF_CloseDocument(output_doc); | 1124 FPDF_CloseDocument(output_doc); |
| 1106 return buffer; | 1125 return buffer; |
| 1107 } | 1126 } |
| 1108 | 1127 |
| 1109 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { | 1128 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { |
| 1129 if (!client_) |
| 1130 return pp::Buffer_Dev(); |
| 1131 |
| 1110 int page_count = FPDF_GetPageCount(doc); | 1132 int page_count = FPDF_GetPageCount(doc); |
| 1111 bool flatten_succeeded = true; | 1133 bool flatten_succeeded = true; |
| 1112 for (int i = 0; i < page_count; ++i) { | 1134 for (int i = 0; i < page_count; ++i) { |
| 1113 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1135 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| 1114 DCHECK(page); | 1136 DCHECK(page); |
| 1115 if (page) { | 1137 if (page) { |
| 1116 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); | 1138 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); |
| 1117 FPDF_ClosePage(page); | 1139 FPDF_ClosePage(page); |
| 1118 if (flatten_ret == FLATTEN_FAIL) { | 1140 if (flatten_ret == FLATTEN_FAIL) { |
| 1119 flatten_succeeded = false; | 1141 flatten_succeeded = false; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 for (int i = 0; i < num_pages; ++i) { | 1226 for (int i = 0; i < num_pages; ++i) { |
| 1205 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1227 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| 1206 TransformPDFPageForPrinting(page, print_settings); | 1228 TransformPDFPageForPrinting(page, print_settings); |
| 1207 FPDF_ClosePage(page); | 1229 FPDF_ClosePage(page); |
| 1208 } | 1230 } |
| 1209 } | 1231 } |
| 1210 } | 1232 } |
| 1211 | 1233 |
| 1212 void PDFiumEngine::SaveSelectedFormForPrint() { | 1234 void PDFiumEngine::SaveSelectedFormForPrint() { |
| 1213 FORM_ForceToKillFocus(form_); | 1235 FORM_ForceToKillFocus(form_); |
| 1236 if (!client_) |
| 1237 return; |
| 1214 client_->FormTextFieldFocusChange(false); | 1238 client_->FormTextFieldFocusChange(false); |
| 1215 } | 1239 } |
| 1216 | 1240 |
| 1217 void PDFiumEngine::PrintEnd() { | 1241 void PDFiumEngine::PrintEnd() { |
| 1218 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1242 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
| 1219 } | 1243 } |
| 1220 | 1244 |
| 1221 PDFiumPage::Area PDFiumEngine::GetCharIndex( | 1245 PDFiumPage::Area PDFiumEngine::GetCharIndex( |
| 1222 const pp::MouseInputEvent& event, int* page_index, | 1246 const pp::MouseInputEvent& event, int* page_index, |
| 1223 int* char_index, PDFiumPage::LinkTarget* target) { | 1247 int* char_index, PDFiumPage::LinkTarget* target) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1250 if (progressive_paints_[i].page_index == page) | 1274 if (progressive_paints_[i].page_index == page) |
| 1251 return PDFiumPage::NONSELECTABLE_AREA; | 1275 return PDFiumPage::NONSELECTABLE_AREA; |
| 1252 } | 1276 } |
| 1253 | 1277 |
| 1254 *page_index = page; | 1278 *page_index = page; |
| 1255 return pages_[page]->GetCharIndex(point, current_rotation_, char_index, | 1279 return pages_[page]->GetCharIndex(point, current_rotation_, char_index, |
| 1256 target); | 1280 target); |
| 1257 } | 1281 } |
| 1258 | 1282 |
| 1259 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { | 1283 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
| 1284 if (!client_) |
| 1285 return false; |
| 1286 |
| 1260 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) | 1287 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) |
| 1261 return false; | 1288 return false; |
| 1262 | 1289 |
| 1263 SelectionChangeInvalidator selection_invalidator(this); | 1290 SelectionChangeInvalidator selection_invalidator(this); |
| 1264 selection_.clear(); | 1291 selection_.clear(); |
| 1265 | 1292 |
| 1266 int page_index = -1; | 1293 int page_index = -1; |
| 1267 int char_index = -1; | 1294 int char_index = -1; |
| 1268 PDFiumPage::LinkTarget target; | 1295 PDFiumPage::LinkTarget target; |
| 1269 PDFiumPage::Area area = GetCharIndex(event, &page_index, | 1296 PDFiumPage::Area area = GetCharIndex(event, &page_index, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 } | 1388 } |
| 1362 | 1389 |
| 1363 if (!selecting_) | 1390 if (!selecting_) |
| 1364 return false; | 1391 return false; |
| 1365 | 1392 |
| 1366 selecting_ = false; | 1393 selecting_ = false; |
| 1367 return true; | 1394 return true; |
| 1368 } | 1395 } |
| 1369 | 1396 |
| 1370 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1397 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
| 1398 if (!client_) |
| 1399 return false; |
| 1400 |
| 1371 int page_index = -1; | 1401 int page_index = -1; |
| 1372 int char_index = -1; | 1402 int char_index = -1; |
| 1373 PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, NULL); | 1403 PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, NULL); |
| 1374 if (!selecting_) { | 1404 if (!selecting_) { |
| 1375 PP_CursorType_Dev cursor; | 1405 PP_CursorType_Dev cursor; |
| 1376 switch (area) { | 1406 switch (area) { |
| 1377 case PDFiumPage::TEXT_AREA: | 1407 case PDFiumPage::TEXT_AREA: |
| 1378 cursor = PP_CURSORTYPE_IBEAM; | 1408 cursor = PP_CURSORTYPE_IBEAM; |
| 1379 break; | 1409 break; |
| 1380 case PDFiumPage::WEBLINK_AREA: | 1410 case PDFiumPage::WEBLINK_AREA: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 | 1512 |
| 1483 int count = pages_[page_index]->GetCharCount(); | 1513 int count = pages_[page_index]->GetCharCount(); |
| 1484 selection_.push_back( | 1514 selection_.push_back( |
| 1485 PDFiumRange(pages_[page_index], count, count - char_index)); | 1515 PDFiumRange(pages_[page_index], count, count - char_index)); |
| 1486 } | 1516 } |
| 1487 | 1517 |
| 1488 return true; | 1518 return true; |
| 1489 } | 1519 } |
| 1490 | 1520 |
| 1491 bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { | 1521 bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { |
| 1522 if (!client_) |
| 1523 return false; |
| 1524 |
| 1492 if (last_page_mouse_down_ == -1) | 1525 if (last_page_mouse_down_ == -1) |
| 1493 return false; | 1526 return false; |
| 1494 | 1527 |
| 1495 bool rv = !!FORM_OnKeyDown( | 1528 bool rv = !!FORM_OnKeyDown( |
| 1496 form_, pages_[last_page_mouse_down_]->GetPage(), | 1529 form_, pages_[last_page_mouse_down_]->GetPage(), |
| 1497 event.GetKeyCode(), event.GetModifiers()); | 1530 event.GetKeyCode(), event.GetModifiers()); |
| 1498 | 1531 |
| 1499 if (event.GetKeyCode() == ui::VKEY_BACK || | 1532 if (event.GetKeyCode() == ui::VKEY_BACK || |
| 1500 event.GetKeyCode() == ui::VKEY_ESCAPE) { | 1533 event.GetKeyCode() == ui::VKEY_ESCAPE) { |
| 1501 // Chrome doesn't send char events for backspace or escape keys, see | 1534 // Chrome doesn't send char events for backspace or escape keys, see |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1531 return false; | 1564 return false; |
| 1532 | 1565 |
| 1533 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 1566 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
| 1534 return !!FORM_OnChar( | 1567 return !!FORM_OnChar( |
| 1535 form_, pages_[last_page_mouse_down_]->GetPage(), | 1568 form_, pages_[last_page_mouse_down_]->GetPage(), |
| 1536 str[0], | 1569 str[0], |
| 1537 event.GetModifiers()); | 1570 event.GetModifiers()); |
| 1538 } | 1571 } |
| 1539 | 1572 |
| 1540 void PDFiumEngine::StartFind(const char* text, bool case_sensitive) { | 1573 void PDFiumEngine::StartFind(const char* text, bool case_sensitive) { |
| 1574 if (!client_) |
| 1575 return; |
| 1576 |
| 1541 // We can get a call to StartFind before we have any page information (i.e. | 1577 // We can get a call to StartFind before we have any page information (i.e. |
| 1542 // before the first call to LoadDocument has happened). Handle this case. | 1578 // before the first call to LoadDocument has happened). Handle this case. |
| 1543 if (pages_.empty()) | 1579 if (pages_.empty()) |
| 1544 return; | 1580 return; |
| 1545 | 1581 |
| 1546 bool first_search = false; | 1582 bool first_search = false; |
| 1547 int character_to_start_searching_from = 0; | 1583 int character_to_start_searching_from = 0; |
| 1548 if (current_find_text_ != text) { // First time we search for this text. | 1584 if (current_find_text_ != text) { // First time we search for this text. |
| 1549 first_search = true; | 1585 first_search = true; |
| 1550 std::vector<PDFiumRange> old_selection = selection_; | 1586 std::vector<PDFiumRange> old_selection = selection_; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 } | 1681 } |
| 1646 | 1682 |
| 1647 FPDFText_FindClose(find); | 1683 FPDFText_FindClose(find); |
| 1648 } | 1684 } |
| 1649 | 1685 |
| 1650 void PDFiumEngine::SearchUsingICU(const base::string16& term, | 1686 void PDFiumEngine::SearchUsingICU(const base::string16& term, |
| 1651 bool case_sensitive, | 1687 bool case_sensitive, |
| 1652 bool first_search, | 1688 bool first_search, |
| 1653 int character_to_start_searching_from, | 1689 int character_to_start_searching_from, |
| 1654 int current_page) { | 1690 int current_page) { |
| 1691 if (!client_) |
| 1692 return; |
| 1693 |
| 1655 base::string16 page_text; | 1694 base::string16 page_text; |
| 1656 int text_length = pages_[current_page]->GetCharCount(); | 1695 int text_length = pages_[current_page]->GetCharCount(); |
| 1657 if (character_to_start_searching_from) { | 1696 if (character_to_start_searching_from) { |
| 1658 text_length -= character_to_start_searching_from; | 1697 text_length -= character_to_start_searching_from; |
| 1659 } else if (!first_search && | 1698 } else if (!first_search && |
| 1660 last_character_index_to_search_ != -1 && | 1699 last_character_index_to_search_ != -1 && |
| 1661 current_page == last_page_to_search_) { | 1700 current_page == last_page_to_search_) { |
| 1662 text_length = last_character_index_to_search_; | 1701 text_length = last_character_index_to_search_; |
| 1663 } | 1702 } |
| 1664 if (text_length <= 0) | 1703 if (text_length <= 0) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1679 int start = FPDFText_GetCharIndexFromTextIndex( | 1718 int start = FPDFText_GetCharIndexFromTextIndex( |
| 1680 pages_[current_page]->GetTextPage(), temp_start); | 1719 pages_[current_page]->GetTextPage(), temp_start); |
| 1681 int end = FPDFText_GetCharIndexFromTextIndex( | 1720 int end = FPDFText_GetCharIndexFromTextIndex( |
| 1682 pages_[current_page]->GetTextPage(), | 1721 pages_[current_page]->GetTextPage(), |
| 1683 temp_start + results[i].length); | 1722 temp_start + results[i].length); |
| 1684 AddFindResult(PDFiumRange(pages_[current_page], start, end - start)); | 1723 AddFindResult(PDFiumRange(pages_[current_page], start, end - start)); |
| 1685 } | 1724 } |
| 1686 } | 1725 } |
| 1687 | 1726 |
| 1688 void PDFiumEngine::AddFindResult(const PDFiumRange& result) { | 1727 void PDFiumEngine::AddFindResult(const PDFiumRange& result) { |
| 1728 if (!client_) |
| 1729 return; |
| 1730 |
| 1689 // Figure out where to insert the new location, since we could have | 1731 // Figure out where to insert the new location, since we could have |
| 1690 // started searching midway and now we wrapped. | 1732 // started searching midway and now we wrapped. |
| 1691 size_t i; | 1733 size_t i; |
| 1692 int page_index = result.page_index(); | 1734 int page_index = result.page_index(); |
| 1693 int char_index = result.char_index(); | 1735 int char_index = result.char_index(); |
| 1694 for (i = 0; i < find_results_.size(); ++i) { | 1736 for (i = 0; i < find_results_.size(); ++i) { |
| 1695 if (find_results_[i].page_index() > page_index || | 1737 if (find_results_[i].page_index() > page_index || |
| 1696 (find_results_[i].page_index() == page_index && | 1738 (find_results_[i].page_index() == page_index && |
| 1697 find_results_[i].char_index() > char_index)) { | 1739 find_results_[i].char_index() > char_index)) { |
| 1698 break; | 1740 break; |
| 1699 } | 1741 } |
| 1700 } | 1742 } |
| 1701 find_results_.insert(find_results_.begin() + i, result); | 1743 find_results_.insert(find_results_.begin() + i, result); |
| 1702 UpdateTickMarks(); | 1744 UpdateTickMarks(); |
| 1703 | 1745 |
| 1704 if (current_find_index_ == -1) { | 1746 if (current_find_index_ == -1) { |
| 1705 // Select the first match. | 1747 // Select the first match. |
| 1706 SelectFindResult(true); | 1748 SelectFindResult(true); |
| 1707 } else if (static_cast<int>(i) <= current_find_index_) { | 1749 } else if (static_cast<int>(i) <= current_find_index_) { |
| 1708 // Update the current match index | 1750 // Update the current match index |
| 1709 current_find_index_++; | 1751 current_find_index_++; |
| 1710 client_->NotifySelectedFindResultChanged(current_find_index_); | 1752 client_->NotifySelectedFindResultChanged(current_find_index_); |
| 1711 } | 1753 } |
| 1712 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false); | 1754 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false); |
| 1713 } | 1755 } |
| 1714 | 1756 |
| 1715 bool PDFiumEngine::SelectFindResult(bool forward) { | 1757 bool PDFiumEngine::SelectFindResult(bool forward) { |
| 1758 if (!client_) |
| 1759 return false; |
| 1760 |
| 1716 if (find_results_.empty()) { | 1761 if (find_results_.empty()) { |
| 1717 NOTREACHED(); | 1762 NOTREACHED(); |
| 1718 return false; | 1763 return false; |
| 1719 } | 1764 } |
| 1720 | 1765 |
| 1721 SelectionChangeInvalidator selection_invalidator(this); | 1766 SelectionChangeInvalidator selection_invalidator(this); |
| 1722 | 1767 |
| 1723 // Move back/forward through the search locations we previously found. | 1768 // Move back/forward through the search locations we previously found. |
| 1724 if (forward) { | 1769 if (forward) { |
| 1725 if (++current_find_index_ == static_cast<int>(find_results_.size())) | 1770 if (++current_find_index_ == static_cast<int>(find_results_.size())) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 next_page_to_search_ = -1; | 1822 next_page_to_search_ = -1; |
| 1778 last_page_to_search_ = -1; | 1823 last_page_to_search_ = -1; |
| 1779 last_character_index_to_search_ = -1; | 1824 last_character_index_to_search_ = -1; |
| 1780 current_find_index_ = -1; | 1825 current_find_index_ = -1; |
| 1781 current_find_text_.clear(); | 1826 current_find_text_.clear(); |
| 1782 UpdateTickMarks(); | 1827 UpdateTickMarks(); |
| 1783 find_factory_.CancelAll(); | 1828 find_factory_.CancelAll(); |
| 1784 } | 1829 } |
| 1785 | 1830 |
| 1786 void PDFiumEngine::UpdateTickMarks() { | 1831 void PDFiumEngine::UpdateTickMarks() { |
| 1832 if (!client_) |
| 1833 return; |
| 1834 |
| 1787 std::vector<pp::Rect> tickmarks; | 1835 std::vector<pp::Rect> tickmarks; |
| 1788 for (size_t i = 0; i < find_results_.size(); ++i) { | 1836 for (size_t i = 0; i < find_results_.size(); ++i) { |
| 1789 pp::Rect rect; | 1837 pp::Rect rect; |
| 1790 // Always use an origin of 0,0 since scroll positions don't affect tickmark. | 1838 // Always use an origin of 0,0 since scroll positions don't affect tickmark. |
| 1791 std::vector<pp::Rect> rects = find_results_[i].GetScreenRects( | 1839 std::vector<pp::Rect> rects = find_results_[i].GetScreenRects( |
| 1792 pp::Point(0, 0), current_zoom_, current_rotation_); | 1840 pp::Point(0, 0), current_zoom_, current_rotation_); |
| 1793 for (size_t j = 0; j < rects.size(); ++j) | 1841 for (size_t j = 0; j < rects.size(); ++j) |
| 1794 rect = rect.Union(rects[j]); | 1842 rect = rect.Union(rects[j]); |
| 1795 tickmarks.push_back(rect); | 1843 tickmarks.push_back(rect); |
| 1796 } | 1844 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1811 current_rotation_ = (current_rotation_ + 1) % 4; | 1859 current_rotation_ = (current_rotation_ + 1) % 4; |
| 1812 InvalidateAllPages(); | 1860 InvalidateAllPages(); |
| 1813 } | 1861 } |
| 1814 | 1862 |
| 1815 void PDFiumEngine::RotateCounterclockwise() { | 1863 void PDFiumEngine::RotateCounterclockwise() { |
| 1816 current_rotation_ = (current_rotation_ - 1) % 4; | 1864 current_rotation_ = (current_rotation_ - 1) % 4; |
| 1817 InvalidateAllPages(); | 1865 InvalidateAllPages(); |
| 1818 } | 1866 } |
| 1819 | 1867 |
| 1820 void PDFiumEngine::InvalidateAllPages() { | 1868 void PDFiumEngine::InvalidateAllPages() { |
| 1869 if (!client_) |
| 1870 return; |
| 1871 |
| 1821 selection_.clear(); | 1872 selection_.clear(); |
| 1822 find_results_.clear(); | 1873 find_results_.clear(); |
| 1823 | 1874 |
| 1824 CancelPaints(); | 1875 CancelPaints(); |
| 1825 LoadPageInfo(true); | 1876 LoadPageInfo(true); |
| 1826 UpdateTickMarks(); | 1877 UpdateTickMarks(); |
| 1827 client_->Invalidate(pp::Rect(plugin_size_)); | 1878 client_->Invalidate(pp::Rect(plugin_size_)); |
| 1828 } | 1879 } |
| 1829 | 1880 |
| 1830 std::string PDFiumEngine::GetSelectedText() { | 1881 std::string PDFiumEngine::GetSelectedText() { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 } | 1991 } |
| 1941 | 1992 |
| 1942 FPDFBitmap_Destroy(bitmap); | 1993 FPDFBitmap_Destroy(bitmap); |
| 1943 } | 1994 } |
| 1944 | 1995 |
| 1945 void PDFiumEngine::SetGrayscale(bool grayscale) { | 1996 void PDFiumEngine::SetGrayscale(bool grayscale) { |
| 1946 render_grayscale_ = grayscale; | 1997 render_grayscale_ = grayscale; |
| 1947 } | 1998 } |
| 1948 | 1999 |
| 1949 void PDFiumEngine::OnCallback(int id) { | 2000 void PDFiumEngine::OnCallback(int id) { |
| 2001 if (!client_) |
| 2002 return; |
| 2003 |
| 1950 if (!timers_.count(id)) | 2004 if (!timers_.count(id)) |
| 1951 return; | 2005 return; |
| 1952 | 2006 |
| 1953 timers_[id].second(id); | 2007 timers_[id].second(id); |
| 1954 if (timers_.count(id)) // The callback might delete the timer. | 2008 if (timers_.count(id)) // The callback might delete the timer. |
| 1955 client_->ScheduleCallback(id, timers_[id].first); | 2009 client_->ScheduleCallback(id, timers_[id].first); |
| 1956 } | 2010 } |
| 1957 | 2011 |
| 1958 std::string PDFiumEngine::GetPageAsJSON(int index) { | 2012 std::string PDFiumEngine::GetPageAsJSON(int index) { |
| 1959 if (!(HasPermission(PERMISSION_COPY) || | 2013 if (!(HasPermission(PERMISSION_COPY) || |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1970 base::JSONWriter::Write(node.get(), &page_json); | 2024 base::JSONWriter::Write(node.get(), &page_json); |
| 1971 return page_json; | 2025 return page_json; |
| 1972 } | 2026 } |
| 1973 | 2027 |
| 1974 bool PDFiumEngine::GetPrintScaling() { | 2028 bool PDFiumEngine::GetPrintScaling() { |
| 1975 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); | 2029 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); |
| 1976 } | 2030 } |
| 1977 | 2031 |
| 1978 void PDFiumEngine::AppendBlankPages(int num_pages) { | 2032 void PDFiumEngine::AppendBlankPages(int num_pages) { |
| 1979 DCHECK(num_pages != 0); | 2033 DCHECK(num_pages != 0); |
| 2034 if (!client_) |
| 2035 return; |
| 1980 | 2036 |
| 1981 if (!doc_) | 2037 if (!doc_) |
| 1982 return; | 2038 return; |
| 1983 | 2039 |
| 1984 selection_.clear(); | 2040 selection_.clear(); |
| 1985 pending_pages_.clear(); | 2041 pending_pages_.clear(); |
| 1986 | 2042 |
| 1987 // Delete all pages except the first one. | 2043 // Delete all pages except the first one. |
| 1988 while (pages_.size() > 1) { | 2044 while (pages_.size() > 1) { |
| 1989 delete pages_.back(); | 2045 delete pages_.back(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 FPDFPage_New(doc_, i, width_in_points, height_in_points); | 2078 FPDFPage_New(doc_, i, width_in_points, height_in_points); |
| 2023 pages_.push_back(new PDFiumPage(this, i, page_rect, true)); | 2079 pages_.push_back(new PDFiumPage(this, i, page_rect, true)); |
| 2024 } | 2080 } |
| 2025 | 2081 |
| 2026 CalculateVisiblePages(); | 2082 CalculateVisiblePages(); |
| 2027 if (document_size_ != old_document_size) | 2083 if (document_size_ != old_document_size) |
| 2028 client_->DocumentSizeUpdated(document_size_); | 2084 client_->DocumentSizeUpdated(document_size_); |
| 2029 } | 2085 } |
| 2030 | 2086 |
| 2031 void PDFiumEngine::LoadDocument() { | 2087 void PDFiumEngine::LoadDocument() { |
| 2088 if (!client_) |
| 2089 return; |
| 2090 |
| 2032 // Check if the document is ready for loading. If it isn't just bail for now, | 2091 // Check if the document is ready for loading. If it isn't just bail for now, |
| 2033 // we will call LoadDocument() again later. | 2092 // we will call LoadDocument() again later. |
| 2034 if (!doc_ && !doc_loader_.IsDocumentComplete() && | 2093 if (!doc_ && !doc_loader_.IsDocumentComplete() && |
| 2035 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) { | 2094 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) { |
| 2036 return; | 2095 return; |
| 2037 } | 2096 } |
| 2038 | 2097 |
| 2039 // If we're in the middle of getting a password, just return. We will retry | 2098 // If we're in the middle of getting a password, just return. We will retry |
| 2040 // loading the document after we get the password anyway. | 2099 // loading the document after we get the password anyway. |
| 2041 if (getting_password_) | 2100 if (getting_password_) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2072 | 2131 |
| 2073 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) | 2132 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) |
| 2074 *needs_password = true; | 2133 *needs_password = true; |
| 2075 | 2134 |
| 2076 return doc_ != NULL; | 2135 return doc_ != NULL; |
| 2077 } | 2136 } |
| 2078 | 2137 |
| 2079 void PDFiumEngine::GetPasswordAndLoad() { | 2138 void PDFiumEngine::GetPasswordAndLoad() { |
| 2080 getting_password_ = true; | 2139 getting_password_ = true; |
| 2081 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); | 2140 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); |
| 2141 if (!client_) |
| 2142 return; |
| 2143 |
| 2082 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( | 2144 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( |
| 2083 &PDFiumEngine::OnGetPasswordComplete)); | 2145 &PDFiumEngine::OnGetPasswordComplete)); |
| 2084 } | 2146 } |
| 2085 | 2147 |
| 2086 void PDFiumEngine::OnGetPasswordComplete(int32_t result, | 2148 void PDFiumEngine::OnGetPasswordComplete(int32_t result, |
| 2087 const pp::Var& password) { | 2149 const pp::Var& password) { |
| 2088 getting_password_ = false; | 2150 getting_password_ = false; |
| 2089 | 2151 |
| 2090 bool password_given = false; | 2152 bool password_given = false; |
| 2091 std::string password_text; | 2153 std::string password_text; |
| 2092 if (result == PP_OK && password.is_string()) { | 2154 if (result == PP_OK && password.is_string()) { |
| 2093 password_text = password.AsString(); | 2155 password_text = password.AsString(); |
| 2094 if (!password_text.empty()) | 2156 if (!password_text.empty()) |
| 2095 password_given = true; | 2157 password_given = true; |
| 2096 } | 2158 } |
| 2097 ContinueLoadingDocument(password_given, password_text); | 2159 ContinueLoadingDocument(password_given, password_text); |
| 2098 } | 2160 } |
| 2099 | 2161 |
| 2100 void PDFiumEngine::ContinueLoadingDocument( | 2162 void PDFiumEngine::ContinueLoadingDocument( |
| 2101 bool has_password, | 2163 bool has_password, |
| 2102 const std::string& password) { | 2164 const std::string& password) { |
| 2165 if (!client_) |
| 2166 return; |
| 2167 |
| 2103 ScopedUnsupportedFeature scoped_unsupported_feature(this); | 2168 ScopedUnsupportedFeature scoped_unsupported_feature(this); |
| 2104 | 2169 |
| 2105 bool needs_password = false; | 2170 bool needs_password = false; |
| 2106 bool loaded = TryLoadingDoc(has_password, password, &needs_password); | 2171 bool loaded = TryLoadingDoc(has_password, password, &needs_password); |
| 2107 bool password_incorrect = !loaded && has_password && needs_password; | 2172 bool password_incorrect = !loaded && has_password && needs_password; |
| 2108 if (password_incorrect && password_tries_remaining_ > 0) { | 2173 if (password_incorrect && password_tries_remaining_ > 0) { |
| 2109 GetPasswordAndLoad(); | 2174 GetPasswordAndLoad(); |
| 2110 return; | 2175 return; |
| 2111 } | 2176 } |
| 2112 | 2177 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2141 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); | 2206 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); |
| 2142 } | 2207 } |
| 2143 | 2208 |
| 2144 LoadPageInfo(false); | 2209 LoadPageInfo(false); |
| 2145 | 2210 |
| 2146 if (doc_loader_.IsDocumentComplete()) | 2211 if (doc_loader_.IsDocumentComplete()) |
| 2147 FinishLoadingDocument(); | 2212 FinishLoadingDocument(); |
| 2148 } | 2213 } |
| 2149 | 2214 |
| 2150 void PDFiumEngine::LoadPageInfo(bool reload) { | 2215 void PDFiumEngine::LoadPageInfo(bool reload) { |
| 2216 if (!client_) |
| 2217 return; |
| 2218 |
| 2151 pending_pages_.clear(); | 2219 pending_pages_.clear(); |
| 2152 pp::Size old_document_size = document_size_; | 2220 pp::Size old_document_size = document_size_; |
| 2153 document_size_ = pp::Size(); | 2221 document_size_ = pp::Size(); |
| 2154 std::vector<pp::Rect> page_rects; | 2222 std::vector<pp::Rect> page_rects; |
| 2155 int page_count = FPDF_GetPageCount(doc_); | 2223 int page_count = FPDF_GetPageCount(doc_); |
| 2156 bool doc_complete = doc_loader_.IsDocumentComplete(); | 2224 bool doc_complete = doc_loader_.IsDocumentComplete(); |
| 2157 for (int i = 0; i < page_count; ++i) { | 2225 for (int i = 0; i < page_count; ++i) { |
| 2158 if (i != 0) { | 2226 if (i != 0) { |
| 2159 // Add space for horizontal separator. | 2227 // Add space for horizontal separator. |
| 2160 document_size_.Enlarge(0, kPageSeparatorThickness); | 2228 document_size_.Enlarge(0, kPageSeparatorThickness); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 progressive.rect = dirty; | 2384 progressive.rect = dirty; |
| 2317 progressive.page_index = page_index; | 2385 progressive.page_index = page_index; |
| 2318 progressive.bitmap = NULL; | 2386 progressive.bitmap = NULL; |
| 2319 progressive.painted_ = false; | 2387 progressive.painted_ = false; |
| 2320 progressive_paints_.push_back(progressive); | 2388 progressive_paints_.push_back(progressive); |
| 2321 return progressive_paints_.size() - 1; | 2389 return progressive_paints_.size() - 1; |
| 2322 } | 2390 } |
| 2323 | 2391 |
| 2324 bool PDFiumEngine::ContinuePaint(int progressive_index, | 2392 bool PDFiumEngine::ContinuePaint(int progressive_index, |
| 2325 pp::ImageData* image_data) { | 2393 pp::ImageData* image_data) { |
| 2394 if (!client_) |
| 2395 return false; |
| 2396 |
| 2326 #if defined(OS_LINUX) | 2397 #if defined(OS_LINUX) |
| 2327 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 2398 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
| 2328 #endif | 2399 #endif |
| 2329 | 2400 |
| 2330 int rv; | 2401 int rv; |
| 2331 int page_index = progressive_paints_[progressive_index].page_index; | 2402 int page_index = progressive_paints_[progressive_index].page_index; |
| 2332 last_progressive_start_time_ = base::Time::Now(); | 2403 last_progressive_start_time_ = base::Time::Now(); |
| 2333 if (progressive_paints_[progressive_index].bitmap) { | 2404 if (progressive_paints_[progressive_index].bitmap) { |
| 2334 rv = FPDF_RenderPage_Continue( | 2405 rv = FPDF_RenderPage_Continue( |
| 2335 pages_[page_index]->GetPage(), static_cast<IFSDK_PAUSE*>(this)); | 2406 pages_[page_index]->GetPage(), static_cast<IFSDK_PAUSE*>(this)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2346 progressive_paints_[progressive_index].bitmap, | 2417 progressive_paints_[progressive_index].bitmap, |
| 2347 pages_[page_index]->GetPage(), start_x, start_y, size_x, size_y, | 2418 pages_[page_index]->GetPage(), start_x, start_y, size_x, size_y, |
| 2348 current_rotation_, | 2419 current_rotation_, |
| 2349 GetRenderingFlags(), static_cast<IFSDK_PAUSE*>(this)); | 2420 GetRenderingFlags(), static_cast<IFSDK_PAUSE*>(this)); |
| 2350 } | 2421 } |
| 2351 return rv != FPDF_RENDER_TOBECOUNTINUED; | 2422 return rv != FPDF_RENDER_TOBECOUNTINUED; |
| 2352 } | 2423 } |
| 2353 | 2424 |
| 2354 void PDFiumEngine::FinishPaint(int progressive_index, | 2425 void PDFiumEngine::FinishPaint(int progressive_index, |
| 2355 pp::ImageData* image_data) { | 2426 pp::ImageData* image_data) { |
| 2427 if (!client_) |
| 2428 return; |
| 2429 |
| 2356 int page_index = progressive_paints_[progressive_index].page_index; | 2430 int page_index = progressive_paints_[progressive_index].page_index; |
| 2357 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2431 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
| 2358 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; | 2432 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; |
| 2359 int start_x, start_y, size_x, size_y; | 2433 int start_x, start_y, size_x, size_y; |
| 2360 GetPDFiumRect( | 2434 GetPDFiumRect( |
| 2361 page_index, dirty_in_screen, &start_x, &start_y, &size_x, &size_y); | 2435 page_index, dirty_in_screen, &start_x, &start_y, &size_x, &size_y); |
| 2362 | 2436 |
| 2363 // Draw the forms. | 2437 // Draw the forms. |
| 2364 FPDF_FFLDraw( | 2438 FPDF_FFLDraw( |
| 2365 form_, bitmap, pages_[page_index]->GetPage(), start_x, start_y, size_x, | 2439 form_, bitmap, pages_[page_index]->GetPage(), start_x, start_y, size_x, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 *start_x = page_rect.x(); | 2613 *start_x = page_rect.x(); |
| 2540 *start_y = page_rect.y(); | 2614 *start_y = page_rect.y(); |
| 2541 *size_x = page_rect.width(); | 2615 *size_x = page_rect.width(); |
| 2542 *size_y = page_rect.height(); | 2616 *size_y = page_rect.height(); |
| 2543 } | 2617 } |
| 2544 | 2618 |
| 2545 int PDFiumEngine::GetRenderingFlags() const { | 2619 int PDFiumEngine::GetRenderingFlags() const { |
| 2546 int flags = FPDF_LCD_TEXT | FPDF_NO_CATCH; | 2620 int flags = FPDF_LCD_TEXT | FPDF_NO_CATCH; |
| 2547 if (render_grayscale_) | 2621 if (render_grayscale_) |
| 2548 flags |= FPDF_GRAYSCALE; | 2622 flags |= FPDF_GRAYSCALE; |
| 2549 if (client_->IsPrintPreview()) | 2623 if (client_ && client_->IsPrintPreview()) |
| 2550 flags |= FPDF_PRINTING; | 2624 flags |= FPDF_PRINTING; |
| 2551 return flags; | 2625 return flags; |
| 2552 } | 2626 } |
| 2553 | 2627 |
| 2554 pp::Rect PDFiumEngine::GetVisibleRect() const { | 2628 pp::Rect PDFiumEngine::GetVisibleRect() const { |
| 2555 pp::Rect rv; | 2629 pp::Rect rv; |
| 2556 rv.set_x(static_cast<int>(position_.x() / current_zoom_)); | 2630 rv.set_x(static_cast<int>(position_.x() / current_zoom_)); |
| 2557 rv.set_y(static_cast<int>(position_.y() / current_zoom_)); | 2631 rv.set_y(static_cast<int>(position_.y() / current_zoom_)); |
| 2558 rv.set_width(static_cast<int>(ceil(plugin_size_.width() / current_zoom_))); | 2632 rv.set_width(static_cast<int>(ceil(plugin_size_.width() / current_zoom_))); |
| 2559 rv.set_height(static_cast<int>(ceil(plugin_size_.height() / current_zoom_))); | 2633 rv.set_height(static_cast<int>(ceil(plugin_size_.height() / current_zoom_))); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 for (size_t i = 0; i < new_selections.size(); ++i) { | 2708 for (size_t i = 0; i < new_selections.size(); ++i) { |
| 2635 for (size_t j = 0; j < old_selections_.size(); ++j) { | 2709 for (size_t j = 0; j < old_selections_.size(); ++j) { |
| 2636 if (new_selections[i] == old_selections_[j]) { | 2710 if (new_selections[i] == old_selections_[j]) { |
| 2637 // Rectangle was selected before and after, so no need to invalidate it. | 2711 // Rectangle was selected before and after, so no need to invalidate it. |
| 2638 // Mark the rectangles by setting them to empty. | 2712 // Mark the rectangles by setting them to empty. |
| 2639 new_selections[i] = old_selections_[j] = pp::Rect(); | 2713 new_selections[i] = old_selections_[j] = pp::Rect(); |
| 2640 } | 2714 } |
| 2641 } | 2715 } |
| 2642 } | 2716 } |
| 2643 | 2717 |
| 2644 for (size_t i = 0; i < old_selections_.size(); ++i) { | 2718 if (engine_->client_) { |
| 2645 if (!old_selections_[i].IsEmpty()) | 2719 for (size_t i = 0; i < old_selections_.size(); ++i) { |
| 2646 engine_->client_->Invalidate(old_selections_[i]); | 2720 if (!old_selections_[i].IsEmpty()) |
| 2647 } | 2721 engine_->client_->Invalidate(old_selections_[i]); |
| 2648 for (size_t i = 0; i < new_selections.size(); ++i) { | 2722 } |
| 2649 if (!new_selections[i].IsEmpty()) | 2723 for (size_t i = 0; i < new_selections.size(); ++i) { |
| 2650 engine_->client_->Invalidate(new_selections[i]); | 2724 if (!new_selections[i].IsEmpty()) |
| 2725 engine_->client_->Invalidate(new_selections[i]); |
| 2726 } |
| 2651 } | 2727 } |
| 2652 engine_->OnSelectionChanged(); | 2728 engine_->OnSelectionChanged(); |
| 2653 } | 2729 } |
| 2654 | 2730 |
| 2655 void | 2731 void |
| 2656 PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( | 2732 PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( |
| 2657 std::vector<pp::Rect>* rects) { | 2733 std::vector<pp::Rect>* rects) { |
| 2658 pp::Rect visible_rect = engine_->GetVisibleRect(); | 2734 pp::Rect visible_rect = engine_->GetVisibleRect(); |
| 2659 for (size_t i = 0; i < engine_->selection_.size(); ++i) { | 2735 for (size_t i = 0; i < engine_->selection_.size(); ++i) { |
| 2660 int page_index = engine_->selection_[i].page_index(); | 2736 int page_index = engine_->selection_[i].page_index(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2696 | 2772 |
| 2697 void PDFiumEngine::SetCurrentPage(int index) { | 2773 void PDFiumEngine::SetCurrentPage(int index) { |
| 2698 if (index == most_visible_page_ || !form_) | 2774 if (index == most_visible_page_ || !form_) |
| 2699 return; | 2775 return; |
| 2700 if (most_visible_page_ != -1 && called_do_document_action_) { | 2776 if (most_visible_page_ != -1 && called_do_document_action_) { |
| 2701 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); | 2777 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); |
| 2702 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); | 2778 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); |
| 2703 } | 2779 } |
| 2704 most_visible_page_ = index; | 2780 most_visible_page_ = index; |
| 2705 #if defined(OS_LINUX) | 2781 #if defined(OS_LINUX) |
| 2782 if (client_) |
| 2706 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 2783 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
| 2707 #endif | 2784 #endif |
| 2708 if (most_visible_page_ != -1 && called_do_document_action_) { | 2785 if (most_visible_page_ != -1 && called_do_document_action_) { |
| 2709 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); | 2786 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); |
| 2710 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); | 2787 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); |
| 2711 } | 2788 } |
| 2712 } | 2789 } |
| 2713 | 2790 |
| 2714 void PDFiumEngine::TransformPDFPageForPrinting( | 2791 void PDFiumEngine::TransformPDFPageForPrinting( |
| 2715 FPDF_PAGE page, | 2792 FPDF_PAGE page, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2856 double right, | 2933 double right, |
| 2857 double bottom) { | 2934 double bottom) { |
| 2858 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 2935 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 2859 int page_index = engine->GetVisiblePageIndex(page); | 2936 int page_index = engine->GetVisiblePageIndex(page); |
| 2860 if (page_index == -1) { | 2937 if (page_index == -1) { |
| 2861 // This can sometime happen when the page is closed because it went off | 2938 // This can sometime happen when the page is closed because it went off |
| 2862 // screen, and PDFium invalidates the control as it's being deleted. | 2939 // screen, and PDFium invalidates the control as it's being deleted. |
| 2863 return; | 2940 return; |
| 2864 } | 2941 } |
| 2865 | 2942 |
| 2943 if (!engine->client_) |
| 2944 return; |
| 2945 |
| 2866 pp::Rect rect = engine->pages_[page_index]->PageToScreen( | 2946 pp::Rect rect = engine->pages_[page_index]->PageToScreen( |
| 2867 engine->GetVisibleRect().point(), engine->current_zoom_, left, top, right, | 2947 engine->GetVisibleRect().point(), engine->current_zoom_, left, top, right, |
| 2868 bottom, engine->current_rotation_); | 2948 bottom, engine->current_rotation_); |
| 2869 engine->client_->Invalidate(rect); | 2949 engine->client_->Invalidate(rect); |
| 2870 } | 2950 } |
| 2871 | 2951 |
| 2872 void PDFiumEngine::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param, | 2952 void PDFiumEngine::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param, |
| 2873 FPDF_PAGE page, | 2953 FPDF_PAGE page, |
| 2874 double left, | 2954 double left, |
| 2875 double top, | 2955 double top, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2889 | 2969 |
| 2890 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { | 2970 void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) { |
| 2891 // We don't need this since it's not enough to change the cursor in all | 2971 // We don't need this since it's not enough to change the cursor in all |
| 2892 // scenarios. Instead, we check which form field we're under in OnMouseMove. | 2972 // scenarios. Instead, we check which form field we're under in OnMouseMove. |
| 2893 } | 2973 } |
| 2894 | 2974 |
| 2895 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, | 2975 int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param, |
| 2896 int elapse, | 2976 int elapse, |
| 2897 TimerCallback timer_func) { | 2977 TimerCallback timer_func) { |
| 2898 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 2978 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 2979 if (!engine->client_) |
| 2980 return -1; |
| 2981 |
| 2899 engine->timers_[++engine->next_timer_id_] = | 2982 engine->timers_[++engine->next_timer_id_] = |
| 2900 std::pair<int, TimerCallback>(elapse, timer_func); | 2983 std::pair<int, TimerCallback>(elapse, timer_func); |
| 2901 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse); | 2984 engine->client_->ScheduleCallback(engine->next_timer_id_, elapse); |
| 2902 return engine->next_timer_id_; | 2985 return engine->next_timer_id_; |
| 2903 } | 2986 } |
| 2904 | 2987 |
| 2905 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { | 2988 void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) { |
| 2906 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 2989 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 2907 engine->timers_.erase(timer_id); | 2990 engine->timers_.erase(timer_id); |
| 2908 } | 2991 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2953 return engine->pages_[index]->GetPage(); | 3036 return engine->pages_[index]->GetPage(); |
| 2954 } | 3037 } |
| 2955 | 3038 |
| 2956 int PDFiumEngine::Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page) { | 3039 int PDFiumEngine::Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page) { |
| 2957 return 0; | 3040 return 0; |
| 2958 } | 3041 } |
| 2959 | 3042 |
| 2960 void PDFiumEngine::Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param, | 3043 void PDFiumEngine::Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param, |
| 2961 FPDF_BYTESTRING named_action) { | 3044 FPDF_BYTESTRING named_action) { |
| 2962 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3045 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3046 if (!engine->client_) |
| 3047 return; |
| 3048 |
| 2963 std::string action(named_action); | 3049 std::string action(named_action); |
| 2964 if (action == "Print") { | 3050 if (action == "Print") { |
| 2965 engine->client_->Print(); | 3051 engine->client_->Print(); |
| 2966 return; | 3052 return; |
| 2967 } | 3053 } |
| 2968 | 3054 |
| 2969 int index = engine->last_page_mouse_down_; | 3055 int index = engine->last_page_mouse_down_; |
| 2970 /* Don't try to calculate the most visible page if we don't have a left click | 3056 /* Don't try to calculate the most visible page if we don't have a left click |
| 2971 before this event (this code originally copied Form_GetCurrentPage which of | 3057 before this event (this code originally copied Form_GetCurrentPage which of |
| 2972 course needs to do that and which doesn't have recursion). This can end up | 3058 course needs to do that and which doesn't have recursion). This can end up |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2997 FPDF_WIDESTRING value, | 3083 FPDF_WIDESTRING value, |
| 2998 FPDF_DWORD valueLen, | 3084 FPDF_DWORD valueLen, |
| 2999 FPDF_BOOL is_focus) { | 3085 FPDF_BOOL is_focus) { |
| 3000 // Do nothing for now. | 3086 // Do nothing for now. |
| 3001 // TODO(gene): use this signal to trigger OSK. | 3087 // TODO(gene): use this signal to trigger OSK. |
| 3002 } | 3088 } |
| 3003 | 3089 |
| 3004 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, | 3090 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, |
| 3005 FPDF_BYTESTRING uri) { | 3091 FPDF_BYTESTRING uri) { |
| 3006 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3092 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3093 if (!engine->client_) |
| 3094 return; |
| 3007 engine->client_->NavigateTo(std::string(uri), false); | 3095 engine->client_->NavigateTo(std::string(uri), false); |
| 3008 } | 3096 } |
| 3009 | 3097 |
| 3010 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, | 3098 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, |
| 3011 int page_index, | 3099 int page_index, |
| 3012 int zoom_mode, | 3100 int zoom_mode, |
| 3013 float* position_array, | 3101 float* position_array, |
| 3014 int size_of_array) { | 3102 int size_of_array) { |
| 3015 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3103 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3104 if (!engine->client_) |
| 3105 return; |
| 3016 engine->client_->ScrollToPage(page_index); | 3106 engine->client_->ScrollToPage(page_index); |
| 3017 } | 3107 } |
| 3018 | 3108 |
| 3019 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, | 3109 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, |
| 3020 FPDF_WIDESTRING message, | 3110 FPDF_WIDESTRING message, |
| 3021 FPDF_WIDESTRING title, | 3111 FPDF_WIDESTRING title, |
| 3022 int type, | 3112 int type, |
| 3023 int icon) { | 3113 int icon) { |
| 3024 // See fpdfformfill.h for these values. | 3114 // See fpdfformfill.h for these values. |
| 3025 enum AlertType { | 3115 enum AlertType { |
| 3026 ALERT_TYPE_OK = 0, | 3116 ALERT_TYPE_OK = 0, |
| 3027 ALERT_TYPE_OK_CANCEL, | 3117 ALERT_TYPE_OK_CANCEL, |
| 3028 ALERT_TYPE_YES_ON, | 3118 ALERT_TYPE_YES_ON, |
| 3029 ALERT_TYPE_YES_NO_CANCEL | 3119 ALERT_TYPE_YES_NO_CANCEL |
| 3030 }; | 3120 }; |
| 3031 | 3121 |
| 3032 enum AlertResult { | 3122 enum AlertResult { |
| 3033 ALERT_RESULT_OK = 1, | 3123 ALERT_RESULT_OK = 1, |
| 3034 ALERT_RESULT_CANCEL, | 3124 ALERT_RESULT_CANCEL, |
| 3035 ALERT_RESULT_NO, | 3125 ALERT_RESULT_NO, |
| 3036 ALERT_RESULT_YES | 3126 ALERT_RESULT_YES |
| 3037 }; | 3127 }; |
| 3038 | 3128 |
| 3039 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3129 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3130 if (!engine->client_) |
| 3131 return ALERT_RESULT_CANCEL; |
| 3132 |
| 3040 std::string message_str = | 3133 std::string message_str = |
| 3041 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | 3134 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); |
| 3042 if (type == ALERT_TYPE_OK) { | 3135 if (type == ALERT_TYPE_OK) { |
| 3043 engine->client_->Alert(message_str); | 3136 engine->client_->Alert(message_str); |
| 3044 return ALERT_RESULT_OK; | 3137 return ALERT_RESULT_OK; |
| 3045 } | 3138 } |
| 3046 | 3139 |
| 3047 bool rv = engine->client_->Confirm(message_str); | 3140 bool rv = engine->client_->Confirm(message_str); |
| 3048 if (type == ALERT_TYPE_OK_CANCEL) | 3141 if (type == ALERT_TYPE_OK_CANCEL) |
| 3049 return rv ? ALERT_RESULT_OK : ALERT_RESULT_CANCEL; | 3142 return rv ? ALERT_RESULT_OK : ALERT_RESULT_CANCEL; |
| 3050 return rv ? ALERT_RESULT_YES : ALERT_RESULT_NO; | 3143 return rv ? ALERT_RESULT_YES : ALERT_RESULT_NO; |
| 3051 } | 3144 } |
| 3052 | 3145 |
| 3053 void PDFiumEngine::Form_Beep(IPDF_JSPLATFORM* param, int type) { | 3146 void PDFiumEngine::Form_Beep(IPDF_JSPLATFORM* param, int type) { |
| 3054 // Beeps are annoying, and not possible using javascript, so ignore for now. | 3147 // Beeps are annoying, and not possible using javascript, so ignore for now. |
| 3055 } | 3148 } |
| 3056 | 3149 |
| 3057 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, | 3150 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, |
| 3058 FPDF_WIDESTRING question, | 3151 FPDF_WIDESTRING question, |
| 3059 FPDF_WIDESTRING title, | 3152 FPDF_WIDESTRING title, |
| 3060 FPDF_WIDESTRING default_response, | 3153 FPDF_WIDESTRING default_response, |
| 3061 FPDF_WIDESTRING label, | 3154 FPDF_WIDESTRING label, |
| 3062 FPDF_BOOL password, | 3155 FPDF_BOOL password, |
| 3063 void* response, | 3156 void* response, |
| 3064 int length) { | 3157 int length) { |
| 3158 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3159 if (!engine->client_) |
| 3160 return -1; |
| 3161 |
| 3065 std::string question_str = base::UTF16ToUTF8( | 3162 std::string question_str = base::UTF16ToUTF8( |
| 3066 reinterpret_cast<const base::char16*>(question)); | 3163 reinterpret_cast<const base::char16*>(question)); |
| 3067 std::string default_str = base::UTF16ToUTF8( | 3164 std::string default_str = base::UTF16ToUTF8( |
| 3068 reinterpret_cast<const base::char16*>(default_response)); | 3165 reinterpret_cast<const base::char16*>(default_response)); |
| 3069 | 3166 |
| 3070 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 3071 std::string rv = engine->client_->Prompt(question_str, default_str); | 3167 std::string rv = engine->client_->Prompt(question_str, default_str); |
| 3072 base::string16 rv_16 = base::UTF8ToUTF16(rv); | 3168 base::string16 rv_16 = base::UTF8ToUTF16(rv); |
| 3073 int rv_bytes = rv_16.size() * sizeof(base::char16); | 3169 int rv_bytes = rv_16.size() * sizeof(base::char16); |
| 3074 if (response) { | 3170 if (response) { |
| 3075 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; | 3171 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; |
| 3076 memcpy(response, rv_16.c_str(), bytes_to_copy); | 3172 memcpy(response, rv_16.c_str(), bytes_to_copy); |
| 3077 } | 3173 } |
| 3078 return rv_bytes; | 3174 return rv_bytes; |
| 3079 } | 3175 } |
| 3080 | 3176 |
| 3081 int PDFiumEngine::Form_GetFilePath(IPDF_JSPLATFORM* param, | 3177 int PDFiumEngine::Form_GetFilePath(IPDF_JSPLATFORM* param, |
| 3082 void* file_path, | 3178 void* file_path, |
| 3083 int length) { | 3179 int length) { |
| 3084 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3180 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3181 if (!engine->client_) |
| 3182 return -1; |
| 3183 |
| 3085 std::string rv = engine->client_->GetURL(); | 3184 std::string rv = engine->client_->GetURL(); |
| 3086 if (file_path && rv.size() <= static_cast<size_t>(length)) | 3185 if (file_path && rv.size() <= static_cast<size_t>(length)) |
| 3087 memcpy(file_path, rv.c_str(), rv.size()); | 3186 memcpy(file_path, rv.c_str(), rv.size()); |
| 3088 return rv.size(); | 3187 return rv.size(); |
| 3089 } | 3188 } |
| 3090 | 3189 |
| 3091 void PDFiumEngine::Form_Mail(IPDF_JSPLATFORM* param, | 3190 void PDFiumEngine::Form_Mail(IPDF_JSPLATFORM* param, |
| 3092 void* mail_data, | 3191 void* mail_data, |
| 3093 int length, | 3192 int length, |
| 3094 FPDF_BOOL ui, | 3193 FPDF_BOOL ui, |
| 3095 FPDF_WIDESTRING to, | 3194 FPDF_WIDESTRING to, |
| 3096 FPDF_WIDESTRING subject, | 3195 FPDF_WIDESTRING subject, |
| 3097 FPDF_WIDESTRING cc, | 3196 FPDF_WIDESTRING cc, |
| 3098 FPDF_WIDESTRING bcc, | 3197 FPDF_WIDESTRING bcc, |
| 3099 FPDF_WIDESTRING message) { | 3198 FPDF_WIDESTRING message) { |
| 3100 DCHECK(length == 0); // Don't handle attachments; no way with mailto. | 3199 DCHECK(length == 0); // Don't handle attachments; no way with mailto. |
| 3200 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3201 if (!engine->client_) |
| 3202 return; |
| 3203 |
| 3101 std::string to_str = | 3204 std::string to_str = |
| 3102 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 3205 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| 3103 std::string cc_str = | 3206 std::string cc_str = |
| 3104 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); | 3207 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); |
| 3105 std::string bcc_str = | 3208 std::string bcc_str = |
| 3106 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); | 3209 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); |
| 3107 std::string subject_str = | 3210 std::string subject_str = |
| 3108 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); | 3211 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); |
| 3109 std::string message_str = | 3212 std::string message_str = |
| 3110 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | 3213 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); |
| 3111 | 3214 |
| 3112 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 3113 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); | 3215 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); |
| 3114 } | 3216 } |
| 3115 | 3217 |
| 3116 void PDFiumEngine::Form_Print(IPDF_JSPLATFORM* param, | 3218 void PDFiumEngine::Form_Print(IPDF_JSPLATFORM* param, |
| 3117 FPDF_BOOL ui, | 3219 FPDF_BOOL ui, |
| 3118 int start, | 3220 int start, |
| 3119 int end, | 3221 int end, |
| 3120 FPDF_BOOL silent, | 3222 FPDF_BOOL silent, |
| 3121 FPDF_BOOL shrink_to_fit, | 3223 FPDF_BOOL shrink_to_fit, |
| 3122 FPDF_BOOL print_as_image, | 3224 FPDF_BOOL print_as_image, |
| 3123 FPDF_BOOL reverse, | 3225 FPDF_BOOL reverse, |
| 3124 FPDF_BOOL annotations) { | 3226 FPDF_BOOL annotations) { |
| 3125 // No way to pass the extra information to the print dialog using JavaScript. | 3227 // No way to pass the extra information to the print dialog using JavaScript. |
| 3126 // Just opening it is fine for now. | 3228 // Just opening it is fine for now. |
| 3127 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3229 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3230 if (!engine->client_) |
| 3231 return; |
| 3128 engine->client_->Print(); | 3232 engine->client_->Print(); |
| 3129 } | 3233 } |
| 3130 | 3234 |
| 3131 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, | 3235 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, |
| 3132 void* form_data, | 3236 void* form_data, |
| 3133 int length, | 3237 int length, |
| 3134 FPDF_WIDESTRING url) { | 3238 FPDF_WIDESTRING url) { |
| 3239 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3240 if (!engine->client_) |
| 3241 return; |
| 3135 std::string url_str = | 3242 std::string url_str = |
| 3136 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 3243 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 3137 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 3138 engine->client_->SubmitForm(url_str, form_data, length); | 3244 engine->client_->SubmitForm(url_str, form_data, length); |
| 3139 } | 3245 } |
| 3140 | 3246 |
| 3141 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, | 3247 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, |
| 3142 int page_number) { | 3248 int page_number) { |
| 3143 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3249 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3250 if (!engine->client_) |
| 3251 return; |
| 3144 engine->client_->ScrollToPage(page_number); | 3252 engine->client_->ScrollToPage(page_number); |
| 3145 } | 3253 } |
| 3146 | 3254 |
| 3147 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, | 3255 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, |
| 3148 void* file_path, | 3256 void* file_path, |
| 3149 int length) { | 3257 int length) { |
| 3150 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3258 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3259 if (!engine->client_) |
| 3260 return -1; |
| 3261 |
| 3151 std::string path = engine->client_->ShowFileSelectionDialog(); | 3262 std::string path = engine->client_->ShowFileSelectionDialog(); |
| 3152 if (path.size() + 1 <= static_cast<size_t>(length)) | 3263 if (path.size() + 1 <= static_cast<size_t>(length)) |
| 3153 memcpy(file_path, &path[0], path.size() + 1); | 3264 memcpy(file_path, &path[0], path.size() + 1); |
| 3154 return path.size() + 1; | 3265 return path.size() + 1; |
| 3155 } | 3266 } |
| 3156 | 3267 |
| 3157 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) { | 3268 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) { |
| 3158 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3269 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3159 return (base::Time::Now() - engine->last_progressive_start_time_). | 3270 return (base::Time::Now() - engine->last_progressive_start_time_). |
| 3160 InMilliseconds() > engine->progressive_paint_timeout_; | 3271 InMilliseconds() > engine->progressive_paint_timeout_; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3397 double* height) { | 3508 double* height) { |
| 3398 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3509 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3399 if (!doc) | 3510 if (!doc) |
| 3400 return false; | 3511 return false; |
| 3401 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3512 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3402 FPDF_CloseDocument(doc); | 3513 FPDF_CloseDocument(doc); |
| 3403 return success; | 3514 return success; |
| 3404 } | 3515 } |
| 3405 | 3516 |
| 3406 } // namespace chrome_pdf | 3517 } // namespace chrome_pdf |
| OLD | NEW |