Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 654 // This is just for testing, needs to be removed later |
| 655 #if defined(WIN32) | 655 #if defined(WIN32) |
| 656 #define XFA_TESTFILE(filename) "E:/"#filename | 656 #define XFA_TESTFILE(filename) "E:/"#filename |
|
Lei Zhang
2016/02/18 01:13:11
Remove?
Tom Sepez
2016/02/18 17:52:44
Done.
| |
| 657 #else | 657 #else |
| 658 #define XFA_TESTFILE(filename) "/home/"#filename | 658 #define XFA_TESTFILE(filename) "/home/"#filename |
| 659 #endif | 659 #endif |
| 660 | 660 |
| 661 struct FPDF_FILE { | 661 struct FPDF_FILE { |
| 662 FPDF_FILEHANDLER file_handler; | 662 FPDF_FILEHANDLER file_handler; |
| 663 FILE* file; | 663 FILE* file; |
| 664 }; | 664 }; |
| 665 | 665 |
| 666 void Sample_Release(FPDF_LPVOID client_data) { | 666 void Sample_Release(FPDF_LPVOID client_data) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 if (!client_data) | 705 if (!client_data) |
| 706 return -1; | 706 return -1; |
| 707 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; | 707 FPDF_FILE* file_wrapper = (FPDF_FILE*)client_data; |
| 708 if (fseek(file_wrapper->file, (long)offset, SEEK_SET)) | 708 if (fseek(file_wrapper->file, (long)offset, SEEK_SET)) |
| 709 return -1; | 709 return -1; |
| 710 // Write data | 710 // Write data |
| 711 size_t write_size = fwrite(buffer, 1, size, file_wrapper->file); | 711 size_t write_size = fwrite(buffer, 1, size, file_wrapper->file); |
| 712 return write_size == size ? 0 : -1; | 712 return write_size == size ? 0 : -1; |
| 713 } | 713 } |
| 714 | 714 |
| 715 FPDF_RESULT Sample_Flush(FPDF_LPVOID client_data) { | 715 FPDF_RESULT Sample_Flush(FPDF_LPVOID client_data) { |
|
Lei Zhang
2016/02/18 01:13:11
Are we going to get warnings / errors about Sample
Tom Sepez
2016/02/18 17:52:44
Not anymore - I removed all this.
| |
| 716 if (!client_data) | 716 if (!client_data) |
| 717 return -1; | 717 return -1; |
| 718 // Flush file | 718 // Flush file |
| 719 fflush(((FPDF_FILE*)client_data)->file); | 719 fflush(((FPDF_FILE*)client_data)->file); |
| 720 return 0; | 720 return 0; |
| 721 } | 721 } |
| 722 | 722 |
| 723 FPDF_RESULT Sample_Truncate(FPDF_LPVOID client_data, FPDF_DWORD size) { | 723 FPDF_RESULT Sample_Truncate(FPDF_LPVOID client_data, FPDF_DWORD size) { |
| 724 return 0; | 724 return 0; |
| 725 } | 725 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 FPDF_FILEHANDLER* file_handle, | 869 FPDF_FILEHANDLER* file_handle, |
| 870 int file_flag, | 870 int file_flag, |
| 871 FPDF_WIDESTRING to) { | 871 FPDF_WIDESTRING to) { |
| 872 std::string to_str = | 872 std::string to_str = |
| 873 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 873 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| 874 // TODO: needs the full implementation of form uploading | 874 // TODO: needs the full implementation of form uploading |
| 875 } | 875 } |
| 876 | 876 |
| 877 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, | 877 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, |
| 878 FPDF_WIDESTRING url) { | 878 FPDF_WIDESTRING url) { |
| 879 std::string url_str = | 879 // NOTE: Think hard about the security implications before allowing |
| 880 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 880 // a PDF file to perform this action. |
| 881 | 881 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 } | 882 } |
| 899 | 883 |
| 900 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, | 884 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, |
| 901 int file_flag, | 885 int file_flag, |
| 902 FPDF_WIDESTRING url, | 886 FPDF_WIDESTRING url, |
| 903 const char* mode) { | 887 const char* mode) { |
| 904 std::string url_str = url ? | 888 // NOTE: Think hard about the security implications before allowing |
| 905 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)) : "NULL"; | 889 // a PDF file to perform this action. |
| 906 | 890 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 } | 891 } |
| 921 | 892 |
| 922 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, | 893 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, |
| 923 FPDF_DOCUMENT document, | 894 FPDF_DOCUMENT document, |
| 924 FPDF_WIDESTRING url) { | 895 FPDF_WIDESTRING url) { |
| 925 std::string url_str = | 896 std::string url_str = |
| 926 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 897 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 927 // TODO: needs to implement GOTO URL action | 898 // TODO: needs to implement GOTO URL action |
| 928 } | 899 } |
| 929 | 900 |
| (...skipping 3041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3971 double* height) { | 3942 double* height) { |
| 3972 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3943 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3973 if (!doc) | 3944 if (!doc) |
| 3974 return false; | 3945 return false; |
| 3975 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3946 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3976 FPDF_CloseDocument(doc); | 3947 FPDF_CloseDocument(doc); |
| 3977 return success; | 3948 return success; |
| 3978 } | 3949 } |
| 3979 | 3950 |
| 3980 } // namespace chrome_pdf | 3951 } // namespace chrome_pdf |
| OLD | NEW |