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 | 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 file_availability_.loader = &doc_loader_; | 590 file_availability_.loader = &doc_loader_; |
| 591 | 591 |
| 592 download_hints_.version = 1; | 592 download_hints_.version = 1; |
| 593 download_hints_.AddSegment = &AddSegment; | 593 download_hints_.AddSegment = &AddSegment; |
| 594 download_hints_.loader = &doc_loader_; | 594 download_hints_.loader = &doc_loader_; |
| 595 | 595 |
| 596 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct | 596 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct |
| 597 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in | 597 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in |
| 598 // callbacks to ourself instead of maintaining a map of them to | 598 // callbacks to ourself instead of maintaining a map of them to |
| 599 // PDFiumEngine. | 599 // PDFiumEngine. |
| 600 FPDF_FORMFILLINFO::version = 1; | 600 FPDF_FORMFILLINFO::version = 1; |
|
Tom Sepez
2014/11/06 17:45:45
New fields are added to this structure, but the ve
Bo Xu
2014/11/06 18:52:05
Since we are branching out xfa, the version in xfa
| |
| 601 FPDF_FORMFILLINFO::m_pJsPlatform = this; | 601 FPDF_FORMFILLINFO::m_pJsPlatform = this; |
|
Tom Sepez
2014/11/06 18:10:05
Note that in going from the pre-xfa version of str
Bo Xu
2014/11/06 18:52:05
If I understand correctly, I should move
IPDF_JSP
| |
| 602 FPDF_FORMFILLINFO::Release = NULL; | 602 FPDF_FORMFILLINFO::Release = NULL; |
| 603 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate; | 603 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate; |
| 604 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect; | 604 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect; |
| 605 FPDF_FORMFILLINFO::FFI_SetCursor = Form_SetCursor; | 605 FPDF_FORMFILLINFO::FFI_SetCursor = Form_SetCursor; |
| 606 FPDF_FORMFILLINFO::FFI_SetTimer = Form_SetTimer; | 606 FPDF_FORMFILLINFO::FFI_SetTimer = Form_SetTimer; |
| 607 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; | 607 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; |
| 608 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; | 608 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; |
| 609 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; | 609 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; |
| 610 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; | 610 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; |
| 611 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; | 611 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; |
| 612 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; | 612 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; |
| 613 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction; | 613 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction; |
| 614 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; | 614 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; |
| 615 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; | 615 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; |
| 616 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; | 616 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; |
| 617 | 617 #ifdef PDF_USE_XFA |
| 618 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; | |
| 619 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; | |
| 620 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; | |
| 621 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; | |
| 622 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; | |
| 623 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; | |
| 624 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; | |
| 625 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; | |
| 626 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; | |
| 627 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; | |
| 628 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; | |
| 629 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; | |
| 630 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; | |
| 631 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; | |
| 632 #endif // PDF_USE_XFA | |
| 618 IPDF_JSPLATFORM::version = 1; | 633 IPDF_JSPLATFORM::version = 1; |
| 619 IPDF_JSPLATFORM::app_alert = Form_Alert; | 634 IPDF_JSPLATFORM::app_alert = Form_Alert; |
| 620 IPDF_JSPLATFORM::app_beep = Form_Beep; | 635 IPDF_JSPLATFORM::app_beep = Form_Beep; |
| 621 IPDF_JSPLATFORM::app_response = Form_Response; | 636 IPDF_JSPLATFORM::app_response = Form_Response; |
| 622 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; | 637 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; |
| 623 IPDF_JSPLATFORM::Doc_mail = Form_Mail; | 638 IPDF_JSPLATFORM::Doc_mail = Form_Mail; |
| 624 IPDF_JSPLATFORM::Doc_print = Form_Print; | 639 IPDF_JSPLATFORM::Doc_print = Form_Print; |
| 625 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; | 640 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; |
| 626 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; | 641 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; |
| 627 IPDF_JSPLATFORM::Field_browse = Form_Browse; | 642 IPDF_JSPLATFORM::Field_browse = Form_Browse; |
| 628 | 643 |
| 629 IFSDK_PAUSE::version = 1; | 644 IFSDK_PAUSE::version = 1; |
| 630 IFSDK_PAUSE::user = NULL; | 645 IFSDK_PAUSE::user = NULL; |
| 631 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; | 646 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; |
| 632 } | 647 } |
| 633 | 648 |
| 634 PDFiumEngine::~PDFiumEngine() { | 649 PDFiumEngine::~PDFiumEngine() { |
| 635 for (size_t i = 0; i < pages_.size(); ++i) | 650 for (size_t i = 0; i < pages_.size(); ++i) |
| 636 pages_[i]->Unload(); | 651 pages_[i]->Unload(); |
| 637 | 652 |
| 638 if (doc_) { | 653 if (doc_) { |
| 639 if (form_) { | 654 if (form_) { |
| 640 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); | 655 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| 656 } | |
| 657 FPDF_CloseDocument(doc_); | |
| 658 if (form_) { | |
| 641 FPDFDOC_ExitFormFillEnviroument(form_); | 659 FPDFDOC_ExitFormFillEnviroument(form_); |
| 642 } | 660 } |
| 643 FPDF_CloseDocument(doc_); | |
| 644 } | 661 } |
| 645 | 662 |
| 646 if (fpdf_availability_) | 663 if (fpdf_availability_) |
| 647 FPDFAvail_Destroy(fpdf_availability_); | 664 FPDFAvail_Destroy(fpdf_availability_); |
| 648 | 665 |
| 649 STLDeleteElements(&pages_); | 666 STLDeleteElements(&pages_); |
| 650 } | 667 } |
| 651 | 668 |
| 669 #ifdef PDF_USE_XFA | |
| 670 | |
| 671 // This is just for testing, needs to be removed later | |
| 672 #if defined(WIN32) | |
| 673 #define XFA_TESTFILE(filename) "E:/"#filename | |
| 674 #else | |
| 675 #define XFA_TESTFILE(filename) "/home/"#filename | |
| 676 #endif | |
| 677 | |
| 678 struct FPDF_FILE { | |
| 679 FPDF_FILEHANDLER fileHandler; | |
|
Lei Zhang
2014/11/06 19:15:29
nit: file_handler
| |
| 680 FILE* file; | |
| 681 }; | |
| 682 | |
| 683 void Sample_Release(FPDF_LPVOID cilent_data) { | |
|
Lei Zhang
2014/11/06 19:15:30
cilent -> client
| |
| 684 if (!cilent_data) | |
| 685 return; | |
| 686 FPDF_FILE* file_wrapper = (FPDF_FILE*)cilent_data; | |
| 687 fclose(file_wrapper->file); | |
| 688 delete file_wrapper; | |
| 689 } | |
| 690 | |
| 691 FPDF_DWORD Sample_GetSize(FPDF_LPVOID cilent_data) { | |
| 692 if (!cilent_data) | |
| 693 return 0; | |
| 694 FPDF_FILE* file_wrapper = (FPDF_FILE*)cilent_data; | |
| 695 long cur_pos = ftell(file_wrapper->file); | |
|
Lei Zhang
2014/11/06 19:15:30
ftell() and fseek() can fail and return -1
| |
| 696 fseek(file_wrapper->file, 0, SEEK_END); | |
| 697 long size = ftell(file_wrapper->file); | |
| 698 fseek(file_wrapper->file, cur_pos, SEEK_SET); | |
| 699 return (FPDF_DWORD)size; | |
| 700 } | |
| 701 | |
| 702 FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID cilent_data, | |
| 703 FPDF_DWORD offset, | |
| 704 FPDF_LPVOID buffer, | |
| 705 FPDF_DWORD size) { | |
| 706 if (!cilent_data) | |
| 707 return -1; | |
| 708 FPDF_FILE* file_wrapper = (FPDF_FILE*)cilent_data; | |
| 709 fseek(file_wrapper->file, (long)offset, SEEK_SET); | |
| 710 size_t read_size = fread(buffer, 1, size, file_wrapper->file); | |
| 711 return read_size == size ? 0 : -1; | |
| 712 } | |
| 713 | |
| 714 FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID cilent_data, | |
| 715 FPDF_DWORD offset, | |
| 716 FPDF_LPCVOID buffer, | |
| 717 FPDF_DWORD size) { | |
| 718 if (!cilent_data) | |
| 719 return -1; | |
| 720 FPDF_FILE* file_wrapper = (FPDF_FILE*)cilent_data; | |
| 721 fseek(file_wrapper->file, (long)offset, SEEK_SET); | |
| 722 // Write data | |
| 723 size_t write_size = fwrite(buffer, 1, size, file_wrapper->file); | |
| 724 return write_size == size ? 0 : -1; | |
| 725 } | |
| 726 | |
| 727 FPDF_RESULT Sample_Flush(FPDF_LPVOID cilent_data) { | |
| 728 if (!cilent_data) | |
| 729 return -1; | |
| 730 // Flush file | |
| 731 fflush(((FPDF_FILE*)cilent_data)->file); | |
| 732 return 0; | |
| 733 } | |
| 734 | |
| 735 FPDF_RESULT Sample_Truncate(FPDF_LPVOID cilent_data, FPDF_DWORD size) { | |
| 736 return 0; | |
| 737 } | |
| 738 | |
| 739 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, | |
| 740 FPDF_FILEHANDLER* file_handler, | |
| 741 FPDF_WIDESTRING to, | |
| 742 FPDF_WIDESTRING subject, | |
| 743 FPDF_WIDESTRING cc, | |
| 744 FPDF_WIDESTRING bcc, | |
| 745 FPDF_WIDESTRING message) { | |
| 746 std::string to_str = | |
| 747 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | |
| 748 std::string subject_str = | |
| 749 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); | |
| 750 std::string cc_str = | |
| 751 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); | |
| 752 std::string bcc_str = | |
| 753 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); | |
| 754 std::string message_str = | |
| 755 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | |
| 756 | |
| 757 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 758 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); | |
| 759 } | |
| 760 | |
| 761 void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* param, | |
| 762 FPDF_PAGE page, | |
| 763 FPDF_BOOL visible, | |
| 764 double left, | |
| 765 double top, | |
| 766 double right, | |
| 767 double bottom) { | |
| 768 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 769 engine->client_->UpdateCursor(PP_CURSORTYPE_IBEAM); | |
| 770 std::vector<pp::Rect> tickmarks; | |
| 771 pp::Rect rect(left, top, right, bottom); | |
| 772 tickmarks.push_back(rect); | |
| 773 engine->client_->UpdateTickMarks(tickmarks); | |
| 774 } | |
| 775 | |
| 776 void PDFiumEngine::Form_SetCurrentPage(FPDF_FORMFILLINFO* param, | |
| 777 FPDF_DOCUMENT document, | |
| 778 int page) { | |
| 779 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 780 pp::Rect page_view_rect = engine->GetPageContentsRect(page); | |
| 781 engine->ScrolledToYPosition(page_view_rect.height()); | |
| 782 pp::Point pos(1, page_view_rect.height()); | |
| 783 engine->SetScrollPosition(pos); | |
| 784 } | |
| 785 | |
| 786 int PDFiumEngine::Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* param, | |
| 787 FPDF_DOCUMENT document) { | |
| 788 int page_index = -1; | |
|
Lei Zhang
2014/11/06 19:15:29
you don't need this variable, just return the GetM
| |
| 789 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 790 page_index = engine->GetMostVisiblePage(); | |
| 791 return page_index; | |
| 792 } | |
| 793 | |
| 794 void PDFiumEngine::Form_GetPageViewRect(FPDF_FORMFILLINFO* param, | |
| 795 FPDF_PAGE page, | |
| 796 double* left, | |
| 797 double* top, | |
| 798 double* right, | |
| 799 double* bottom) { | |
| 800 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | |
| 801 int page_index = engine->GetMostVisiblePage(); | |
| 802 pp::Rect page_view_rect = engine->GetPageContentsRect(page_index); | |
| 803 | |
| 804 *left = page_view_rect.x(); | |
| 805 *right = page_view_rect.width() + page_view_rect.x(); | |
|
Lei Zhang
2014/11/06 19:15:29
pp::Rect has right() and bottom() methods, but no
| |
| 806 *top = page_view_rect.y(); | |
| 807 *bottom = page_view_rect.height(); | |
| 808 | |
| 809 std::string javascript = "alert(\"PageViewRect:" | |
|
Lei Zhang
2014/11/06 19:15:29
another unused variable, more below
| |
| 810 + base::DoubleToString(*left) + "," | |
| 811 + base::DoubleToString(*right) + "," | |
| 812 + base::DoubleToString(*top) + "," | |
| 813 + base::DoubleToString(*bottom) + "," | |
| 814 + "\")"; | |
| 815 } | |
| 816 | |
| 817 int PDFiumEngine::Form_GetPlatform(FPDF_FORMFILLINFO* param, | |
| 818 void* platform, | |
| 819 int length) { | |
| 820 int platform_flag = -1; | |
| 821 | |
| 822 #if defined(WIN32) | |
| 823 platform_flag = 0; | |
| 824 #elif defined(__linux__) | |
| 825 platform_flag = 1; | |
| 826 #else | |
| 827 platform_flag = 2; | |
| 828 #endif | |
| 829 | |
| 830 std::string javascript = "alert(\"Platform:" | |
| 831 + base::DoubleToString(platform_flag) | |
| 832 + "\")"; | |
| 833 | |
| 834 return 3; | |
|
Lei Zhang
2014/11/06 19:15:30
why doesn't this return |platform_flag| ?
| |
| 835 } | |
| 836 | |
| 837 FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* param, | |
| 838 FPDF_PAGE page, | |
| 839 FPDF_WIDGET widget, | |
| 840 int menu_flag, | |
| 841 float x, | |
| 842 float y) { | |
| 843 return false; | |
| 844 } | |
| 845 | |
| 846 FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* param, | |
| 847 FPDF_WIDESTRING url, | |
| 848 FPDF_WIDESTRING data, | |
| 849 FPDF_WIDESTRING content_type, | |
| 850 FPDF_WIDESTRING encode, | |
| 851 FPDF_WIDESTRING header, | |
| 852 FPDF_BSTR* response) { | |
| 853 std::string url_str = | |
| 854 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 855 std::string data_str = | |
| 856 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | |
| 857 std::string content_type_str = | |
| 858 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(content_type)); | |
| 859 std::string encode_str = | |
| 860 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | |
| 861 std::string header_str = | |
| 862 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(header)); | |
| 863 | |
| 864 std::string javascript = "alert(\"Post:" | |
| 865 + url_str + "," + data_str + "," + content_type_str + "," | |
| 866 + encode_str + "," + header_str | |
| 867 + "\")"; | |
| 868 return true; | |
| 869 } | |
| 870 | |
| 871 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* param, | |
| 872 FPDF_WIDESTRING url, | |
| 873 FPDF_WIDESTRING data, | |
| 874 FPDF_WIDESTRING encode) { | |
| 875 std::string url_str = | |
| 876 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 877 std::string data_str = | |
| 878 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | |
| 879 std::string encode_str = | |
| 880 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | |
| 881 | |
| 882 std::string javascript = "alert(\"Put:" | |
| 883 + url_str + "," + data_str + "," + encode_str | |
| 884 + "\")"; | |
| 885 | |
| 886 return true; | |
| 887 } | |
| 888 | |
| 889 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* param, | |
| 890 FPDF_FILEHANDLER* file_handle, | |
| 891 int file_flag, | |
| 892 FPDF_WIDESTRING dest) { | |
| 893 std::string to_str = | |
| 894 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(dest)); | |
| 895 // TODO: needs the full implementation of form uploading | |
| 896 } | |
| 897 | |
| 898 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, | |
| 899 FPDF_WIDESTRING url) { | |
| 900 std::string url_str = | |
| 901 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 902 | |
| 903 // Now should get data from url. | |
| 904 // For testing purpose, use data read from file | |
| 905 // TODO: needs the full implementation here | |
| 906 FILE* file = fopen(XFA_TESTFILE("downloadtest.tem"), "w"); | |
| 907 | |
| 908 FPDF_FILE* file_wrapper = new FPDF_FILE; | |
| 909 file_wrapper->file = file; | |
| 910 file_wrapper->fileHandler.clientData = file_wrapper; | |
| 911 file_wrapper->fileHandler.Flush = Sample_Flush; | |
| 912 file_wrapper->fileHandler.GetSize = Sample_GetSize; | |
| 913 file_wrapper->fileHandler.ReadBlock = Sample_ReadBlock; | |
| 914 file_wrapper->fileHandler.Release = Sample_Release; | |
| 915 file_wrapper->fileHandler.Truncate = Sample_Truncate; | |
| 916 file_wrapper->fileHandler.WriteBlock = Sample_WriteBlock; | |
| 917 | |
| 918 return &file_wrapper->fileHandler; | |
| 919 } | |
| 920 | |
| 921 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, | |
| 922 int file_flag, | |
| 923 FPDF_WIDESTRING url, | |
| 924 const char* mode) { | |
| 925 std::string url_str = "NULL"; | |
| 926 if (url != NULL) { | |
| 927 url_str = | |
| 928 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 929 } | |
| 930 if (strncmp(mode, "wb", 2) == 0) { | |
| 931 FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); | |
| 932 FPDF_FILE* file_wrapper = new FPDF_FILE; | |
| 933 file_wrapper->file = file; | |
| 934 file_wrapper->fileHandler.clientData = file_wrapper; | |
| 935 file_wrapper->fileHandler.Flush = Sample_Flush; | |
| 936 file_wrapper->fileHandler.GetSize = Sample_GetSize; | |
| 937 file_wrapper->fileHandler.ReadBlock = Sample_ReadBlock; | |
| 938 file_wrapper->fileHandler.Release = Sample_Release; | |
| 939 file_wrapper->fileHandler.Truncate = Sample_Truncate; | |
| 940 file_wrapper->fileHandler.WriteBlock = Sample_WriteBlock; | |
| 941 return &file_wrapper->fileHandler; | |
| 942 } else { | |
|
Lei Zhang
2014/11/06 19:15:30
you don't need the else block since you always ret
| |
| 943 url_str = base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 944 } | |
| 945 return NULL; | |
| 946 } | |
| 947 | |
| 948 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, | |
| 949 FPDF_DOCUMENT document, | |
| 950 FPDF_WIDESTRING url) { | |
| 951 std::string url_str = | |
| 952 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 953 // TODO: needs to implement GOTO URL action | |
| 954 } | |
| 955 | |
| 956 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, | |
| 957 void* language, | |
| 958 int length) { | |
| 959 return 0; | |
| 960 } | |
| 961 | |
| 962 #endif // PDF_USE_XFA | |
| 963 | |
| 652 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 964 int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| 653 unsigned char* buffer, unsigned long size) { | 965 unsigned char* buffer, unsigned long size) { |
| 654 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 966 DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| 655 return loader->GetBlock(position, size, buffer); | 967 return loader->GetBlock(position, size, buffer); |
| 656 } | 968 } |
| 657 | 969 |
| 658 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 970 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 659 size_t offset, size_t size) { | 971 size_t offset, size_t size) { |
| 660 PDFiumEngine::FileAvail* file_avail = | 972 PDFiumEngine::FileAvail* file_avail = |
| 661 static_cast<PDFiumEngine::FileAvail*>(param); | 973 static_cast<PDFiumEngine::FileAvail*>(param); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); | 1225 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); |
| 914 } | 1226 } |
| 915 | 1227 |
| 916 if (doc_) // This can only happen if loading |doc_| fails. | 1228 if (doc_) // This can only happen if loading |doc_| fails. |
| 917 client_->DocumentLoadComplete(pages_.size()); | 1229 client_->DocumentLoadComplete(pages_.size()); |
| 918 } | 1230 } |
| 919 | 1231 |
| 920 void PDFiumEngine::UnsupportedFeature(int type) { | 1232 void PDFiumEngine::UnsupportedFeature(int type) { |
| 921 std::string feature; | 1233 std::string feature; |
| 922 switch (type) { | 1234 switch (type) { |
| 1235 #ifndef PDF_USE_XFA | |
| 923 case FPDF_UNSP_DOC_XFAFORM: | 1236 case FPDF_UNSP_DOC_XFAFORM: |
| 924 feature = "XFA"; | 1237 feature = "XFA"; |
| 925 break; | 1238 break; |
| 1239 #endif | |
| 926 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 1240 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 927 feature = "Portfolios_Packages"; | 1241 feature = "Portfolios_Packages"; |
| 928 break; | 1242 break; |
| 929 case FPDF_UNSP_DOC_ATTACHMENT: | 1243 case FPDF_UNSP_DOC_ATTACHMENT: |
| 930 case FPDF_UNSP_ANNOT_ATTACHMENT: | 1244 case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 931 feature = "Attachment"; | 1245 feature = "Attachment"; |
| 932 break; | 1246 break; |
| 933 case FPDF_UNSP_DOC_SECURITY: | 1247 case FPDF_UNSP_DOC_SECURITY: |
| 934 feature = "Rights_Management"; | 1248 feature = "Rights_Management"; |
| 935 break; | 1249 break; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1341 if (page_index != -1) { | 1655 if (page_index != -1) { |
| 1342 last_page_mouse_down_ = page_index; | 1656 last_page_mouse_down_ = page_index; |
| 1343 double page_x, page_y; | 1657 double page_x, page_y; |
| 1344 pp::Point point = event.GetPosition(); | 1658 pp::Point point = event.GetPosition(); |
| 1345 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1659 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1346 | 1660 |
| 1347 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1661 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1348 int control = FPDPage_HasFormFieldAtPoint( | 1662 int control = FPDPage_HasFormFieldAtPoint( |
| 1349 form_, pages_[page_index]->GetPage(), page_x, page_y); | 1663 form_, pages_[page_index]->GetPage(), page_x, page_y); |
| 1350 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1664 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
| 1351 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || | 1665 #ifdef PDF_USE_XFA |
| 1352 control == FPDF_FORMFIELD_COMBOBOX); | 1666 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| 1667 control == FPDF_FORMFIELD_COMBOBOX || control == FPDF_FORMFIELD_XFA); | |
|
Lei Zhang
2014/11/06 19:15:29
nit: 4 space indent on line continuations.
| |
| 1668 #else | |
| 1669 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || | |
| 1670 control == FPDF_FORMFIELD_COMBOBOX); | |
| 1671 #endif | |
| 1353 return true; // Return now before we get into the selection code. | 1672 return true; // Return now before we get into the selection code. |
| 1354 } | 1673 } |
| 1355 } | 1674 } |
| 1356 | 1675 |
| 1357 client_->FormTextFieldFocusChange(false); | 1676 client_->FormTextFieldFocusChange(false); |
| 1358 | 1677 |
| 1359 if (area != PDFiumPage::TEXT_AREA) | 1678 if (area != PDFiumPage::TEXT_AREA) |
| 1360 return true; // Return true so WebKit doesn't do its own highlighting. | 1679 return true; // Return true so WebKit doesn't do its own highlighting. |
| 1361 | 1680 |
| 1362 if (event.GetClickCount() == 1) { | 1681 if (event.GetClickCount() == 1) { |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2227 if (!form_) { | 2546 if (!form_) { |
| 2228 // Only returns 0 when data isn't available. If form data is downloaded, or | 2547 // Only returns 0 when data isn't available. If form data is downloaded, or |
| 2229 // if this isn't a form, returns positive values. | 2548 // if this isn't a form, returns positive values. |
| 2230 if (!doc_loader_.IsDocumentComplete() && | 2549 if (!doc_loader_.IsDocumentComplete() && |
| 2231 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { | 2550 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { |
| 2232 return; | 2551 return; |
| 2233 } | 2552 } |
| 2234 | 2553 |
| 2235 form_ = FPDFDOC_InitFormFillEnviroument( | 2554 form_ = FPDFDOC_InitFormFillEnviroument( |
| 2236 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); | 2555 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); |
| 2556 #ifdef PDF_USE_XFA | |
| 2557 FPDF_LoadXFA(doc_); | |
| 2558 #endif | |
| 2559 | |
| 2237 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); | 2560 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); |
| 2238 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); | 2561 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); |
| 2239 } | 2562 } |
| 2240 | 2563 |
| 2241 if (!doc_loader_.IsDocumentComplete()) { | 2564 if (!doc_loader_.IsDocumentComplete()) { |
| 2242 // Check if the first page is available. In a linearized PDF, that is not | 2565 // Check if the first page is available. In a linearized PDF, that is not |
| 2243 // always page 0. Doing this gives us the default page size, since when the | 2566 // always page 0. Doing this gives us the default page size, since when the |
| 2244 // document is available, the first page is available as well. | 2567 // document is available, the first page is available as well. |
| 2245 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); | 2568 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); |
| 2246 } | 2569 } |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3536 double* height) { | 3859 double* height) { |
| 3537 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3860 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3538 if (!doc) | 3861 if (!doc) |
| 3539 return false; | 3862 return false; |
| 3540 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3863 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3541 FPDF_CloseDocument(doc); | 3864 FPDF_CloseDocument(doc); |
| 3542 return success; | 3865 return success; |
| 3543 } | 3866 } |
| 3544 | 3867 |
| 3545 } // namespace chrome_pdf | 3868 } // namespace chrome_pdf |
| OLD | NEW |