| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 FPDF_CloseDocument(doc_); | 644 FPDF_CloseDocument(doc_); |
| 645 #endif | 645 #endif |
| 646 } | 646 } |
| 647 FPDFAvail_Destroy(fpdf_availability_); | 647 FPDFAvail_Destroy(fpdf_availability_); |
| 648 | 648 |
| 649 STLDeleteElements(&pages_); | 649 STLDeleteElements(&pages_); |
| 650 } | 650 } |
| 651 | 651 |
| 652 #ifdef PDF_USE_XFA | 652 #ifdef PDF_USE_XFA |
| 653 | 653 |
| 654 // This is just for testing, needs to be removed later | |
| 655 #if defined(WIN32) | |
| 656 #define XFA_TESTFILE(filename) "E:/"#filename | |
| 657 #else | |
| 658 #define XFA_TESTFILE(filename) "/home/"#filename | |
| 659 #endif | |
| 660 | |
| 661 struct FPDF_FILE { | |
| 662 FPDF_FILEHANDLER file_handler; | |
| 663 FILE* file; | |
| 664 }; | |
| 665 | |
| 666 void Sample_Release(FPDF_LPVOID client_data) { | |
| 667 if (!client_data) | |
| 668 return; | |
| 669 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; | |
| 670 fclose(file_wrapper->file); | |
| 671 delete file_wrapper; | |
| 672 } | |
| 673 | |
| 674 FPDF_DWORD Sample_GetSize(FPDF_LPVOID client_data) { | |
| 675 if (!client_data) | |
| 676 return 0; | |
| 677 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; | |
| 678 long cur_pos = ftell(file_wrapper->file); | |
| 679 if (cur_pos == -1) | |
| 680 return 0; | |
| 681 if (fseek(file_wrapper->file, 0, SEEK_END)) | |
| 682 return 0; | |
| 683 long size = ftell(file_wrapper->file); | |
| 684 fseek(file_wrapper->file, cur_pos, SEEK_SET); | |
| 685 return (FPDF_DWORD)size; | |
| 686 } | |
| 687 | |
| 688 FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID client_data, | |
| 689 FPDF_DWORD offset, | |
| 690 FPDF_LPVOID buffer, | |
| 691 FPDF_DWORD size) { | |
| 692 if (!client_data) | |
| 693 return -1; | |
| 694 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; | |
| 695 if (fseek(file_wrapper->file, (long)offset, SEEK_SET)) | |
| 696 return -1; | |
| 697 size_t read_size = fread(buffer, 1, size, file_wrapper->file); | |
| 698 return read_size == size ? 0 : -1; | |
| 699 } | |
| 700 | |
| 701 FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID client_data, | |
| 702 FPDF_DWORD offset, | |
| 703 FPDF_LPCVOID buffer, | |
| 704 FPDF_DWORD size) { | |
| 705 if (!client_data) | |
| 706 return -1; | |
| 707 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; | |
| 708 if (fseek(file_wrapper->file, (long)offset, SEEK_SET)) | |
| 709 return -1; | |
| 710 // Write data | |
| 711 size_t write_size = fwrite(buffer, 1, size, file_wrapper->file); | |
| 712 return write_size == size ? 0 : -1; | |
| 713 } | |
| 714 | |
| 715 FPDF_RESULT Sample_Flush(FPDF_LPVOID client_data) { | |
| 716 if (!client_data) | |
| 717 return -1; | |
| 718 // Flush file | |
| 719 fflush(((FPDF_FILE*)client_data)->file); | |
| 720 return 0; | |
| 721 } | |
| 722 | |
| 723 FPDF_RESULT Sample_Truncate(FPDF_LPVOID client_data, FPDF_DWORD size) { | |
| 724 return 0; | |
| 725 } | |
| 726 | |
| 727 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, | 654 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, |
| 728 FPDF_FILEHANDLER* file_handler, | 655 FPDF_FILEHANDLER* file_handler, |
| 729 FPDF_WIDESTRING to, | 656 FPDF_WIDESTRING to, |
| 730 FPDF_WIDESTRING subject, | 657 FPDF_WIDESTRING subject, |
| 731 FPDF_WIDESTRING cc, | 658 FPDF_WIDESTRING cc, |
| 732 FPDF_WIDESTRING bcc, | 659 FPDF_WIDESTRING bcc, |
| 733 FPDF_WIDESTRING message) { | 660 FPDF_WIDESTRING message) { |
| 734 std::string to_str = | 661 std::string to_str = |
| 735 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 662 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| 736 std::string subject_str = | 663 std::string subject_str = |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 FPDF_FILEHANDLER* file_handle, | 796 FPDF_FILEHANDLER* file_handle, |
| 870 int file_flag, | 797 int file_flag, |
| 871 FPDF_WIDESTRING to) { | 798 FPDF_WIDESTRING to) { |
| 872 std::string to_str = | 799 std::string to_str = |
| 873 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 800 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| 874 // TODO: needs the full implementation of form uploading | 801 // TODO: needs the full implementation of form uploading |
| 875 } | 802 } |
| 876 | 803 |
| 877 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, | 804 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, |
| 878 FPDF_WIDESTRING url) { | 805 FPDF_WIDESTRING url) { |
| 879 std::string url_str = | 806 // NOTE: Think hard about the security implications before allowing |
| 880 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 807 // a PDF file to perform this action. |
| 881 | 808 return nullptr; |
| 882 // Now should get data from url. | |
| 883 // For testing purpose, use data read from file | |
| 884 // TODO: needs the full implementation here | |
| 885 FILE* file = fopen(XFA_TESTFILE("downloadtest.tem"), "w"); | |
| 886 | |
| 887 FPDF_FILE* file_wrapper = new FPDF_FILE; | |
| 888 file_wrapper->file = file; | |
| 889 file_wrapper->file_handler.clientData = file_wrapper; | |
| 890 file_wrapper->file_handler.Flush = Sample_Flush; | |
| 891 file_wrapper->file_handler.GetSize = Sample_GetSize; | |
| 892 file_wrapper->file_handler.ReadBlock = Sample_ReadBlock; | |
| 893 file_wrapper->file_handler.Release = Sample_Release; | |
| 894 file_wrapper->file_handler.Truncate = Sample_Truncate; | |
| 895 file_wrapper->file_handler.WriteBlock = Sample_WriteBlock; | |
| 896 | |
| 897 return &file_wrapper->file_handler; | |
| 898 } | 809 } |
| 899 | 810 |
| 900 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, | 811 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, |
| 901 int file_flag, | 812 int file_flag, |
| 902 FPDF_WIDESTRING url, | 813 FPDF_WIDESTRING url, |
| 903 const char* mode) { | 814 const char* mode) { |
| 904 std::string url_str = url ? | 815 // NOTE: Think hard about the security implications before allowing |
| 905 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)) : "NULL"; | 816 // a PDF file to perform this action. |
| 906 | 817 return nullptr; |
| 907 // TODO: need to implement open file from the url | |
| 908 // Use a file path for the ease of testing | |
| 909 FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); | |
| 910 FPDF_FILE* file_wrapper = new FPDF_FILE; | |
| 911 file_wrapper->file = file; | |
| 912 file_wrapper->file_handler.clientData = file_wrapper; | |
| 913 file_wrapper->file_handler.Flush = Sample_Flush; | |
| 914 file_wrapper->file_handler.GetSize = Sample_GetSize; | |
| 915 file_wrapper->file_handler.ReadBlock = Sample_ReadBlock; | |
| 916 file_wrapper->file_handler.Release = Sample_Release; | |
| 917 file_wrapper->file_handler.Truncate = Sample_Truncate; | |
| 918 file_wrapper->file_handler.WriteBlock = Sample_WriteBlock; | |
| 919 return &file_wrapper->file_handler; | |
| 920 } | 818 } |
| 921 | 819 |
| 922 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, | 820 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, |
| 923 FPDF_DOCUMENT document, | 821 FPDF_DOCUMENT document, |
| 924 FPDF_WIDESTRING url) { | 822 FPDF_WIDESTRING url) { |
| 925 std::string url_str = | 823 std::string url_str = |
| 926 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 824 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 927 // TODO: needs to implement GOTO URL action | 825 // TODO: needs to implement GOTO URL action |
| 928 } | 826 } |
| 929 | 827 |
| (...skipping 3041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3971 double* height) { | 3869 double* height) { |
| 3972 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3870 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3973 if (!doc) | 3871 if (!doc) |
| 3974 return false; | 3872 return false; |
| 3975 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3873 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3976 FPDF_CloseDocument(doc); | 3874 FPDF_CloseDocument(doc); |
| 3977 return success; | 3875 return success; |
| 3978 } | 3876 } |
| 3979 | 3877 |
| 3980 } // namespace chrome_pdf | 3878 } // namespace chrome_pdf |
| OLD | NEW |