| 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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; | 580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; |
| 581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; | 581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; |
| 582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; | 582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; |
| 583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; | 583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; |
| 584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; | 584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; |
| 585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; | 585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; |
| 586 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction; | 586 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction; |
| 587 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; | 587 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; |
| 588 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; | 588 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; |
| 589 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; | 589 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; |
| 590 #if defined(PDF_USE_XFA) | 590 #if defined(PDF_ENABLE_XFA) |
| 591 FPDF_FORMFILLINFO::version = 2; | 591 FPDF_FORMFILLINFO::version = 2; |
| 592 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; | 592 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; |
| 593 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; | 593 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; |
| 594 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; | 594 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; |
| 595 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; | 595 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; |
| 596 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; | 596 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; |
| 597 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; | 597 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; |
| 598 FPDF_FORMFILLINFO::FFI_PageEvent = nullptr; | 598 FPDF_FORMFILLINFO::FFI_PageEvent = nullptr; |
| 599 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; | 599 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; |
| 600 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; | 600 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; |
| 601 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; | 601 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; |
| 602 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; | 602 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; |
| 603 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; | 603 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; |
| 604 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; | 604 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; |
| 605 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; | 605 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; |
| 606 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; | 606 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; |
| 607 #endif // defined(PDF_USE_XFA) | 607 #endif // defined(PDF_ENABLE_XFA) |
| 608 IPDF_JSPLATFORM::version = 3; | 608 IPDF_JSPLATFORM::version = 3; |
| 609 IPDF_JSPLATFORM::app_alert = Form_Alert; | 609 IPDF_JSPLATFORM::app_alert = Form_Alert; |
| 610 IPDF_JSPLATFORM::app_beep = Form_Beep; | 610 IPDF_JSPLATFORM::app_beep = Form_Beep; |
| 611 IPDF_JSPLATFORM::app_response = Form_Response; | 611 IPDF_JSPLATFORM::app_response = Form_Response; |
| 612 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; | 612 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; |
| 613 IPDF_JSPLATFORM::Doc_mail = Form_Mail; | 613 IPDF_JSPLATFORM::Doc_mail = Form_Mail; |
| 614 IPDF_JSPLATFORM::Doc_print = Form_Print; | 614 IPDF_JSPLATFORM::Doc_print = Form_Print; |
| 615 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; | 615 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; |
| 616 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; | 616 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; |
| 617 IPDF_JSPLATFORM::Field_browse = Form_Browse; | 617 IPDF_JSPLATFORM::Field_browse = Form_Browse; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 628 #endif | 628 #endif |
| 629 } | 629 } |
| 630 | 630 |
| 631 PDFiumEngine::~PDFiumEngine() { | 631 PDFiumEngine::~PDFiumEngine() { |
| 632 for (auto& page : pages_) | 632 for (auto& page : pages_) |
| 633 page->Unload(); | 633 page->Unload(); |
| 634 | 634 |
| 635 if (doc_) { | 635 if (doc_) { |
| 636 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); | 636 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| 637 | 637 |
| 638 #if defined(PDF_USE_XFA) | 638 #if defined(PDF_ENABLE_XFA) |
| 639 // XFA may require |form_| to outlive |doc_|, so shut down in that order. | 639 // XFA may require |form_| to outlive |doc_|, so shut down in that order. |
| 640 FPDF_CloseDocument(doc_); | 640 FPDF_CloseDocument(doc_); |
| 641 FPDFDOC_ExitFormFillEnvironment(form_); | 641 FPDFDOC_ExitFormFillEnvironment(form_); |
| 642 #else | 642 #else |
| 643 // Normally |doc_| should outlive |form_|. | 643 // Normally |doc_| should outlive |form_|. |
| 644 FPDFDOC_ExitFormFillEnvironment(form_); | 644 FPDFDOC_ExitFormFillEnvironment(form_); |
| 645 FPDF_CloseDocument(doc_); | 645 FPDF_CloseDocument(doc_); |
| 646 #endif | 646 #endif |
| 647 } | 647 } |
| 648 FPDFAvail_Destroy(fpdf_availability_); | 648 FPDFAvail_Destroy(fpdf_availability_); |
| 649 | 649 |
| 650 base::STLDeleteElements(&pages_); | 650 base::STLDeleteElements(&pages_); |
| 651 } | 651 } |
| 652 | 652 |
| 653 #if defined(PDF_USE_XFA) | 653 #if defined(PDF_ENABLE_XFA) |
| 654 | 654 |
| 655 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, | 655 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, |
| 656 FPDF_FILEHANDLER* file_handler, | 656 FPDF_FILEHANDLER* file_handler, |
| 657 FPDF_WIDESTRING to, | 657 FPDF_WIDESTRING to, |
| 658 FPDF_WIDESTRING subject, | 658 FPDF_WIDESTRING subject, |
| 659 FPDF_WIDESTRING cc, | 659 FPDF_WIDESTRING cc, |
| 660 FPDF_WIDESTRING bcc, | 660 FPDF_WIDESTRING bcc, |
| 661 FPDF_WIDESTRING message) { | 661 FPDF_WIDESTRING message) { |
| 662 std::string to_str = | 662 std::string to_str = |
| 663 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 663 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 825 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 826 // TODO: needs to implement GOTO URL action | 826 // TODO: needs to implement GOTO URL action |
| 827 } | 827 } |
| 828 | 828 |
| 829 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, | 829 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, |
| 830 void* language, | 830 void* language, |
| 831 int length) { | 831 int length) { |
| 832 return 0; | 832 return 0; |
| 833 } | 833 } |
| 834 | 834 |
| 835 #endif // defined(PDF_USE_XFA) | 835 #endif // defined(PDF_ENABLE_XFA) |
| 836 | 836 |
| 837 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 837 int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| 838 unsigned char* buffer, unsigned long size) { | 838 unsigned char* buffer, unsigned long size) { |
| 839 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 839 DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| 840 return loader->GetBlock(position, size, buffer); | 840 return loader->GetBlock(position, size, buffer); |
| 841 } | 841 } |
| 842 | 842 |
| 843 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 843 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 844 size_t offset, size_t size) { | 844 size_t offset, size_t size) { |
| 845 PDFiumEngine::FileAvail* file_avail = | 845 PDFiumEngine::FileAvail* file_avail = |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 FPDF_ImportPages(doc_, | 1006 FPDF_ImportPages(doc_, |
| 1007 static_cast<PDFiumEngine*>(engine)->doc(), | 1007 static_cast<PDFiumEngine*>(engine)->doc(), |
| 1008 "1", | 1008 "1", |
| 1009 index); | 1009 index); |
| 1010 pp::Size new_page_size = GetPageSize(index); | 1010 pp::Size new_page_size = GetPageSize(index); |
| 1011 if (curr_page_size != new_page_size) | 1011 if (curr_page_size != new_page_size) |
| 1012 LoadPageInfo(true); | 1012 LoadPageInfo(true); |
| 1013 client_->Invalidate(GetPageScreenRect(index)); | 1013 client_->Invalidate(GetPageScreenRect(index)); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 #if defined(PDF_USE_XFA) | 1016 #if defined(PDF_ENABLE_XFA) |
| 1017 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { | 1017 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { |
| 1018 position_ = position; | 1018 position_ = position; |
| 1019 } | 1019 } |
| 1020 #endif | 1020 #endif |
| 1021 | 1021 |
| 1022 bool PDFiumEngine::IsProgressiveLoad() { | 1022 bool PDFiumEngine::IsProgressiveLoad() { |
| 1023 return doc_loader_.is_partial_document(); | 1023 return doc_loader_.is_partial_document(); |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 std::string PDFiumEngine::GetMetadata(const std::string& key) { | 1026 std::string PDFiumEngine::GetMetadata(const std::string& key) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); | 1118 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 if (doc_) // This can only happen if loading |doc_| fails. | 1121 if (doc_) // This can only happen if loading |doc_| fails. |
| 1122 client_->DocumentLoadComplete(pages_.size()); | 1122 client_->DocumentLoadComplete(pages_.size()); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 void PDFiumEngine::UnsupportedFeature(int type) { | 1125 void PDFiumEngine::UnsupportedFeature(int type) { |
| 1126 std::string feature; | 1126 std::string feature; |
| 1127 switch (type) { | 1127 switch (type) { |
| 1128 #if !defined(PDF_USE_XFA) | 1128 #if !defined(PDF_ENABLE_XFA) |
| 1129 case FPDF_UNSP_DOC_XFAFORM: | 1129 case FPDF_UNSP_DOC_XFAFORM: |
| 1130 feature = "XFA"; | 1130 feature = "XFA"; |
| 1131 break; | 1131 break; |
| 1132 #endif | 1132 #endif |
| 1133 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 1133 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 1134 feature = "Portfolios_Packages"; | 1134 feature = "Portfolios_Packages"; |
| 1135 break; | 1135 break; |
| 1136 case FPDF_UNSP_DOC_ATTACHMENT: | 1136 case FPDF_UNSP_DOC_ATTACHMENT: |
| 1137 case FPDF_UNSP_ANNOT_ATTACHMENT: | 1137 case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 1138 feature = "Attachment"; | 1138 feature = "Attachment"; |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 last_page_mouse_down_ = page_index; | 1561 last_page_mouse_down_ = page_index; |
| 1562 double page_x, page_y; | 1562 double page_x, page_y; |
| 1563 pp::Point point = event.GetPosition(); | 1563 pp::Point point = event.GetPosition(); |
| 1564 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1564 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1565 | 1565 |
| 1566 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1566 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1567 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1567 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
| 1568 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); | 1568 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); |
| 1569 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || | 1569 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || |
| 1570 form_type == FPDF_FORMFIELD_COMBOBOX); | 1570 form_type == FPDF_FORMFIELD_COMBOBOX); |
| 1571 #if defined(PDF_USE_XFA) | 1571 #if defined(PDF_ENABLE_XFA) |
| 1572 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); | 1572 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); |
| 1573 #endif | 1573 #endif |
| 1574 client_->FormTextFieldFocusChange(is_valid_control); | 1574 client_->FormTextFieldFocusChange(is_valid_control); |
| 1575 return true; // Return now before we get into the selection code. | 1575 return true; // Return now before we get into the selection code. |
| 1576 } | 1576 } |
| 1577 } | 1577 } |
| 1578 | 1578 |
| 1579 client_->FormTextFieldFocusChange(false); | 1579 client_->FormTextFieldFocusChange(false); |
| 1580 | 1580 |
| 1581 if (area != PDFiumPage::TEXT_AREA) | 1581 if (area != PDFiumPage::TEXT_AREA) |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 int form_status = | 2525 int form_status = |
| 2526 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_); | 2526 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_); |
| 2527 bool doc_complete = doc_loader_.IsDocumentComplete(); | 2527 bool doc_complete = doc_loader_.IsDocumentComplete(); |
| 2528 // Try again if the data is not available and the document hasn't finished | 2528 // Try again if the data is not available and the document hasn't finished |
| 2529 // downloading. | 2529 // downloading. |
| 2530 if (form_status == PDF_FORM_NOTAVAIL && !doc_complete) | 2530 if (form_status == PDF_FORM_NOTAVAIL && !doc_complete) |
| 2531 return; | 2531 return; |
| 2532 | 2532 |
| 2533 form_ = FPDFDOC_InitFormFillEnvironment( | 2533 form_ = FPDFDOC_InitFormFillEnvironment( |
| 2534 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); | 2534 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); |
| 2535 #if defined(PDF_USE_XFA) | 2535 #if defined(PDF_ENABLE_XFA) |
| 2536 FPDF_LoadXFA(doc_); | 2536 FPDF_LoadXFA(doc_); |
| 2537 #endif | 2537 #endif |
| 2538 | 2538 |
| 2539 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); | 2539 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); |
| 2540 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); | 2540 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); |
| 2541 } | 2541 } |
| 2542 | 2542 |
| 2543 if (!doc_loader_.IsDocumentComplete()) { | 2543 if (!doc_loader_.IsDocumentComplete()) { |
| 2544 // Check if the first page is available. In a linearized PDF, that is not | 2544 // Check if the first page is available. In a linearized PDF, that is not |
| 2545 // always page 0. Doing this gives us the default page size, since when the | 2545 // always page 0. Doing this gives us the default page size, since when the |
| (...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3915 FPDF_DOCUMENT doc = | 3915 FPDF_DOCUMENT doc = |
| 3916 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 3916 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 3917 if (!doc) | 3917 if (!doc) |
| 3918 return false; | 3918 return false; |
| 3919 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3919 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3920 FPDF_CloseDocument(doc); | 3920 FPDF_CloseDocument(doc); |
| 3921 return success; | 3921 return success; |
| 3922 } | 3922 } |
| 3923 | 3923 |
| 3924 } // namespace chrome_pdf | 3924 } // namespace chrome_pdf |
| OLD | NEW |