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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 _TEST_XFA_ |
| 618 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; | |
| 619 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; | |
| 620 //FPDF_FORMFILLINFO::FFI_GetCurDocumentIndex = Form_GetCurDocumentIndex; | |
| 621 //FPDF_FORMFILLINFO::FFI_GetDocumentCount = Form_GetDocumentCount; | |
| 622 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; | |
| 623 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; | |
| 624 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; | |
| 625 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; | |
| 626 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; | |
| 627 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; | |
| 628 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; | |
| 629 // FPDF_FORMFILLINFO::FFI_ShowFileDialog = Form_ShowFileDialog; | |
| 630 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; | |
| 631 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; | |
| 632 // FPDF_FORMFILLINFO::FFI_GetFilePath = MyForm_GetFilePath; | |
| 633 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; | |
| 634 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; | |
| 635 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; | |
| 636 #endif // _TEST_XFA_ | |
| 618 IPDF_JSPLATFORM::version = 1; | 637 IPDF_JSPLATFORM::version = 1; |
| 619 IPDF_JSPLATFORM::app_alert = Form_Alert; | 638 IPDF_JSPLATFORM::app_alert = Form_Alert; |
| 620 IPDF_JSPLATFORM::app_beep = Form_Beep; | 639 IPDF_JSPLATFORM::app_beep = Form_Beep; |
| 621 IPDF_JSPLATFORM::app_response = Form_Response; | 640 IPDF_JSPLATFORM::app_response = Form_Response; |
| 622 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; | 641 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; |
| 623 IPDF_JSPLATFORM::Doc_mail = Form_Mail; | 642 IPDF_JSPLATFORM::Doc_mail = Form_Mail; |
| 624 IPDF_JSPLATFORM::Doc_print = Form_Print; | 643 IPDF_JSPLATFORM::Doc_print = Form_Print; |
| 625 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; | 644 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; |
| 626 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; | 645 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; |
| 627 IPDF_JSPLATFORM::Field_browse = Form_Browse; | 646 IPDF_JSPLATFORM::Field_browse = Form_Browse; |
| 628 | 647 |
| 629 IFSDK_PAUSE::version = 1; | 648 IFSDK_PAUSE::version = 1; |
| 630 IFSDK_PAUSE::user = NULL; | 649 IFSDK_PAUSE::user = NULL; |
| 631 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; | 650 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; |
| 632 } | 651 } |
| 633 | 652 |
| 634 PDFiumEngine::~PDFiumEngine() { | 653 PDFiumEngine::~PDFiumEngine() { |
| 635 for (size_t i = 0; i < pages_.size(); ++i) | 654 for (size_t i = 0; i < pages_.size(); ++i) |
| 636 pages_[i]->Unload(); | 655 pages_[i]->Unload(); |
| 637 | 656 |
| 638 if (doc_) { | 657 if (doc_) { |
| 639 if (form_) { | 658 if (form_) { |
| 640 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); | 659 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| 641 FPDFDOC_ExitFormFillEnviroument(form_); | |
| 642 } | 660 } |
| 643 FPDF_CloseDocument(doc_); | 661 FPDF_CloseDocument(doc_); |
| 662 if (form_) { | |
| 663 FPDFDOC_ExitFormFillEnviroument(form_); | |
| 664 } | |
| 644 } | 665 } |
| 645 | 666 |
| 646 if (fpdf_availability_) | 667 if (fpdf_availability_) |
| 647 FPDFAvail_Destroy(fpdf_availability_); | 668 FPDFAvail_Destroy(fpdf_availability_); |
| 648 | 669 |
| 649 STLDeleteElements(&pages_); | 670 STLDeleteElements(&pages_); |
| 650 } | 671 } |
| 651 | 672 |
| 673 #ifdef _TEST_XFA_ | |
| 674 | |
| 675 typedef struct _FPDF_FILE { | |
| 676 FPDF_FILEHANDLER fileHandler; | |
| 677 FILE* file; | |
| 678 }FPDF_FILE; | |
| 679 | |
| 680 | |
| 681 void Sample_Release(FPDF_LPVOID clientData) { | |
| 682 if (!clientData) return; | |
|
Lei Zhang
2014/11/05 22:45:09
style: return on the next line please.
Bo Xu
2014/11/06 01:26:20
Done.
| |
| 683 | |
| 684 fclose(((FPDF_FILE*)clientData)->file); | |
| 685 delete ((FPDF_FILE*)clientData); | |
| 686 } | |
| 687 | |
| 688 FPDF_DWORD Sample_GetSize(FPDF_LPVOID clientData) { | |
| 689 if (!clientData) return 0; | |
| 690 | |
| 691 long curPos = ftell(((FPDF_FILE*)clientData)->file); | |
| 692 fseek(((FPDF_FILE*)clientData)->file, 0, SEEK_END); | |
| 693 long size = ftell(((FPDF_FILE*)clientData)->file); | |
| 694 fseek(((FPDF_FILE*)clientData)->file, curPos, SEEK_SET); | |
| 695 | |
| 696 return (FPDF_DWORD)size; | |
| 697 } | |
| 698 | |
| 699 FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF _LPVOID buffer, FPDF_DWORD size) { | |
| 700 if (!clientData) return -1; | |
| 701 | |
| 702 fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET); | |
| 703 size_t readSize = fread(buffer, 1, size, ((FPDF_FILE*)clientData)->file) ; | |
| 704 return readSize == size ? 0 : -1; | |
| 705 } | |
| 706 | |
| 707 FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPD F_LPCVOID buffer, FPDF_DWORD size) { | |
| 708 if (!clientData) return -1; | |
| 709 | |
| 710 fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET); | |
| 711 //Write data | |
| 712 size_t writeSize = fwrite(buffer, 1, size, ((FPDF_FILE*)clientData)->fil e); | |
| 713 return writeSize == size ? 0 : -1; | |
| 714 } | |
| 715 | |
| 716 FPDF_RESULT Sample_Flush(FPDF_LPVOID clientData) { | |
| 717 if (!clientData) return -1; | |
| 718 | |
| 719 //Flush file | |
| 720 fflush(((FPDF_FILE*)clientData)->file); | |
| 721 | |
| 722 return 0; | |
| 723 } | |
| 724 | |
| 725 FPDF_RESULT Sample_Truncate(FPDF_LPVOID clientData, FPDF_DWORD size) { | |
| 726 return 0; | |
| 727 } | |
| 728 | |
| 729 | |
| 730 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* pThis, | |
| 731 FPDF_FILEHANDLER* fileHandler, | |
| 732 FPDF_WIDESTRING to, | |
| 733 FPDF_WIDESTRING subject, | |
| 734 FPDF_WIDESTRING cc, | |
| 735 FPDF_WIDESTRING bcc, | |
| 736 FPDF_WIDESTRING message) { | |
| 737 std::string to_str = | |
| 738 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | |
| 739 std::string subject_str = | |
| 740 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject) ); | |
| 741 std::string cc_str = | |
| 742 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); | |
| 743 std::string bcc_str = | |
| 744 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); | |
| 745 std::string message_str = | |
| 746 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message) ); | |
| 747 | |
| 748 PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 749 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str ); | |
| 750 } | |
| 751 | |
| 752 void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* pThis, | |
| 753 FPDF_PAGE page, FPDF_BOOL bVisible, | |
| 754 double left, double top, double right , double bottom) { | |
| 755 PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 756 engine->client_->UpdateCursor(PP_CURSORTYPE_IBEAM); | |
| 757 std::vector<pp::Rect> tickmarks; | |
| 758 pp::Rect rect(left, top, right, bottom); | |
| 759 tickmarks.push_back(rect); | |
| 760 engine->client_->UpdateTickMarks(tickmarks); | |
| 761 } | |
| 762 | |
| 763 //int PDFiumEngine::Form_GetCurDocumentIndex(FPDF_FORMFILLINFO* pThis) { | |
| 764 // PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 765 // engine->client_->RunJSCmd("alert(\"GetCurDocumentIndex\")"); | |
| 766 // return 0; | |
| 767 //} | |
| 768 // | |
| 769 //int PDFiumEngine::Form_GetDocumentCount(FPDF_FORMFILLINFO* pThis) { | |
| 770 // PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 771 // engine->client_->RunJSCmd("alert(\"GetCurDocumentCount\")"); | |
| 772 // return 0; | |
| 773 //} | |
| 774 | |
| 775 void PDFiumEngine::Form_SetCurrentPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT d ocument, int iCurPage) { | |
| 776 PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 777 pp::Rect pageViewRect = engine->GetPageContentsRect(iCurPage); | |
| 778 engine->ScrolledToYPosition(pageViewRect.height()); | |
| 779 pp::Point pos(1, pageViewRect.height()); | |
| 780 engine->SetScrollPosition(pos); | |
| 781 } | |
| 782 | |
| 783 int PDFiumEngine::Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* pThis, FPDF_DOCUME NT document) { | |
| 784 //int pageCount = FPDF_GetPageCount(document); | |
| 785 int pageIndex = -1; | |
| 786 PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 787 pageIndex = engine->GetMostVisiblePage(); | |
| 788 return pageIndex; | |
| 789 } | |
| 790 | |
| 791 void PDFiumEngine::Form_GetPageViewRect(FPDF_FORMFILLINFO* pThis, | |
| 792 FPDF_PAGE page, | |
| 793 double* left, double* top, dou ble* right, double* bottom) { | |
| 794 PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 795 int page_index = engine->GetMostVisiblePage(); | |
| 796 pp::Rect pageViewRect = engine->GetPageContentsRect(page_index); | |
| 797 | |
| 798 *left = pageViewRect.x(); | |
| 799 *right = pageViewRect.width() + pageViewRect.x(); | |
| 800 *top = pageViewRect.y(); | |
| 801 *bottom = pageViewRect.height(); | |
| 802 | |
| 803 std::string javascript = "alert(\"PageViewRect:" | |
| 804 + base::DoubleToString(*left) + "," | |
| 805 + base::DoubleToString(*right) + "," | |
| 806 + base::DoubleToString(*top) + "," | |
| 807 + base::DoubleToString(*bottom) + "," | |
| 808 + "\")"; | |
| 809 | |
| 810 } | |
| 811 | |
| 812 int PDFiumEngine::Form_GetPlatform(FPDF_FORMFILLINFO* pThis, | |
| 813 void* platform, | |
| 814 int length) { | |
| 815 int platform_flag = -1; | |
| 816 #if defined(WIN32) | |
| 817 platform_flag = 0; | |
| 818 #elif defined(__linux__) | |
| 819 platform_flag = 1; | |
| 820 #else | |
| 821 platform_flag = 2; | |
| 822 #endif | |
| 823 std::string javascript = "alert(\"Platform:" | |
| 824 + base::DoubleToString(platform_flag) | |
| 825 + "\")"; | |
| 826 //platform = new char[3]; | |
| 827 //char tem[10] = "WIN"; | |
| 828 //strncpy((char*)platform, tem, 3); | |
| 829 | |
| 830 return 3; | |
| 831 } | |
| 832 | |
| 833 FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* pThis, | |
| 834 FPDF_PAGE page, | |
| 835 FPDF_WIDGET hWidget, | |
| 836 int menuFlag, float x, float y) { | |
| 837 return false; | |
| 838 } | |
| 839 | |
| 840 FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDES TRING wsURL, | |
| 841 FPDF_WIDESTRING wsData, FPDF_WI DESTRING wsContentType, | |
| 842 FPDF_WIDESTRING wsEncode, FPDF_ WIDESTRING wsHeader, FPDF_BSTR* respone) { | |
| 843 std::string url_str = | |
| 844 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); | |
|
Lei Zhang
2014/11/05 22:45:09
Would it be easier to construct the message with F
Bo Xu
2014/11/06 01:26:20
Hmm, seems FPDF_WIDESTRING are const unsigned shor
| |
| 845 std::string data_str = | |
| 846 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData)) ; | |
| 847 std::string content_type_str = | |
| 848 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsConten tType)); | |
| 849 std::string encode_str = | |
| 850 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode )); | |
| 851 std::string header_str = | |
| 852 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsHeader )); | |
| 853 | |
| 854 std::string javascript = "alert(\"Post:" | |
| 855 + url_str + "," + data_str + "," + content_type_str + "," | |
| 856 + encode_str + "," + header_str | |
| 857 + "\")"; | |
| 858 return true; | |
| 859 } | |
| 860 | |
| 861 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* pThis, | |
| 862 FPDF_WIDESTRING wsURL, FPDF_WIDE STRING wsData, FPDF_WIDESTRING wsEncode) { | |
| 863 std::string url_str = | |
| 864 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); | |
| 865 std::string data_str = | |
| 866 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData)) ; | |
| 867 std::string encode_str = | |
| 868 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode )); | |
| 869 | |
| 870 std::string javascript = "alert(\"Put:" | |
| 871 + url_str + "," + data_str + "," + encode_str | |
| 872 + "\")"; | |
| 873 | |
| 874 return true; | |
| 875 } | |
| 876 | |
| 877 //FPDF_BOOL PDFiumEngine::Form_ShowFileDialog(FPDF_FORMFILLINFO* pThis, FPDF_WID ESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE p athArr) { | |
| 878 // int tem = 1; | |
| 879 // tem++; | |
| 880 // return false; | |
| 881 //} | |
| 882 | |
| 883 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fil eHandler, int fileFlag, FPDF_WIDESTRING uploadTo) { | |
| 884 std::string to_str = | |
| 885 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(uploadTo )); | |
| 886 | |
| 887 } | |
| 888 | |
| 889 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL) { | |
| 890 std::string url_str = | |
| 891 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(URL)); | |
| 892 | |
| 893 | |
| 894 // Get URL data... | |
| 895 FILE* file = fopen(XFA_TESTFILE("downloadtest.tem"), "w"); | |
| 896 FPDF_FILE* pFileHander = new FPDF_FILE; | |
| 897 pFileHander->file = file; | |
| 898 pFileHander->fileHandler.clientData = pFileHander; | |
| 899 pFileHander->fileHandler.Flush = Sample_Flush; | |
| 900 pFileHander->fileHandler.GetSize = Sample_GetSize; | |
| 901 pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; | |
| 902 pFileHander->fileHandler.Release = Sample_Release; | |
| 903 pFileHander->fileHandler.Truncate = Sample_Truncate; | |
| 904 pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; | |
| 905 | |
| 906 return &pFileHander->fileHandler; | |
| 907 } | |
| 908 | |
| 909 //FPDF_BOOL PDFiumEngine::MyForm_GetFilePath(FPDF_FORMFILLINFO* pThis, FPDF_FILE HANDLER* pFileHandler, void* filePath, int length) { | |
| 910 // //std::string filePath = engine->client_->FileOpen(fileFlag); | |
| 911 // if (filePath == NULL) { | |
| 912 // std::string javascript = "alert(\"GetFilePath:NULL\")"; | |
| 913 // PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 914 // engine->client_->RunJSCmd(javascript); | |
| 915 // return false; | |
| 916 // } | |
| 917 // std::string filePath_str = (char*)filePath; | |
| 918 // | |
| 919 // std::string javascript = "alert(\"GetFilePath:" + filePath_str + "\")"; | |
| 920 // PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); | |
| 921 // engine->client_->RunJSCmd(javascript); | |
| 922 // | |
| 923 // FILE* file = fopen(FXQA_TESTFILE("tem.xdp"), "w"); | |
| 924 // FPDF_FILE* pFileHander = new FPDF_FILE; | |
| 925 // pFileHander->file = file; | |
| 926 // pFileHander->fileHandler.clientData = pFileHander; | |
| 927 // pFileHander->fileHandler.Flush = Sample_Flush; | |
| 928 // pFileHander->fileHandler.GetSize = Sample_GetSize; | |
| 929 // pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; | |
| 930 // pFileHander->fileHandler.Release = Sample_Release; | |
| 931 // pFileHander->fileHandler.Truncate = Sample_Truncate; | |
| 932 // pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; | |
| 933 // | |
| 934 // pFileHandler = &pFileHander->fileHandler; | |
| 935 // | |
| 936 // return true; | |
| 937 //} | |
| 938 | |
| 939 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* pThis, int file Flag, FPDF_WIDESTRING wsURL, const char* mode) { | |
| 940 std::string url_str = "NULL"; | |
| 941 if (wsURL == NULL) { | |
| 942 url_str = "NULL"; | |
|
Lei Zhang
2014/11/05 22:45:09
It's already initialized to "NULL"
| |
| 943 } | |
| 944 else { | |
| 945 url_str = | |
| 946 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>( wsURL)); | |
| 947 } | |
| 948 if (strncmp(mode, "wb", 2) == 0) { | |
| 949 | |
| 950 FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); | |
| 951 FPDF_FILE* pFileHander = new FPDF_FILE; | |
| 952 pFileHander->file = file; | |
| 953 pFileHander->fileHandler.clientData = pFileHander; | |
| 954 pFileHander->fileHandler.Flush = Sample_Flush; | |
| 955 pFileHander->fileHandler.GetSize = Sample_GetSize; | |
| 956 pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; | |
| 957 pFileHander->fileHandler.Release = Sample_Release; | |
| 958 pFileHander->fileHandler.Truncate = Sample_Truncate; | |
| 959 pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; | |
| 960 return &pFileHander->fileHandler; | |
| 961 } | |
| 962 else { | |
| 963 url_str = base::UTF16ToUTF8(reinterpret_cast<const base::char16* >(wsURL)); | |
| 964 } | |
| 965 return NULL; | |
| 966 } | |
| 967 | |
| 968 | |
| 969 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document , FPDF_WIDESTRING wsURL) { | |
| 970 std::string url_str = | |
| 971 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); | |
| 972 } | |
| 973 | |
| 974 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* pThis, void* language, int length) { | |
| 975 return 0; | |
| 976 } | |
| 977 | |
| 978 #endif // _TEST_XFA_ | |
| 979 | |
| 652 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 980 int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| 653 unsigned char* buffer, unsigned long size) { | 981 unsigned char* buffer, unsigned long size) { |
| 654 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 982 DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| 655 return loader->GetBlock(position, size, buffer); | 983 return loader->GetBlock(position, size, buffer); |
| 656 } | 984 } |
| 657 | 985 |
| 658 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 986 bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 659 size_t offset, size_t size) { | 987 size_t offset, size_t size) { |
| 660 PDFiumEngine::FileAvail* file_avail = | 988 PDFiumEngine::FileAvail* file_avail = |
| 661 static_cast<PDFiumEngine::FileAvail*>(param); | 989 static_cast<PDFiumEngine::FileAvail*>(param); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 } | 1242 } |
| 915 | 1243 |
| 916 if (doc_) // This can only happen if loading |doc_| fails. | 1244 if (doc_) // This can only happen if loading |doc_| fails. |
| 917 client_->DocumentLoadComplete(pages_.size()); | 1245 client_->DocumentLoadComplete(pages_.size()); |
| 918 } | 1246 } |
| 919 | 1247 |
| 920 void PDFiumEngine::UnsupportedFeature(int type) { | 1248 void PDFiumEngine::UnsupportedFeature(int type) { |
| 921 std::string feature; | 1249 std::string feature; |
| 922 switch (type) { | 1250 switch (type) { |
| 923 case FPDF_UNSP_DOC_XFAFORM: | 1251 case FPDF_UNSP_DOC_XFAFORM: |
| 924 feature = "XFA"; | 1252 //feature = "XFA"; |
| 925 break; | 1253 break; |
| 926 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 1254 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 927 feature = "Portfolios_Packages"; | 1255 feature = "Portfolios_Packages"; |
| 928 break; | 1256 break; |
| 929 case FPDF_UNSP_DOC_ATTACHMENT: | 1257 case FPDF_UNSP_DOC_ATTACHMENT: |
| 930 case FPDF_UNSP_ANNOT_ATTACHMENT: | 1258 case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 931 feature = "Attachment"; | 1259 feature = "Attachment"; |
| 932 break; | 1260 break; |
| 933 case FPDF_UNSP_DOC_SECURITY: | 1261 case FPDF_UNSP_DOC_SECURITY: |
| 934 feature = "Rights_Management"; | 1262 feature = "Rights_Management"; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1341 if (page_index != -1) { | 1669 if (page_index != -1) { |
| 1342 last_page_mouse_down_ = page_index; | 1670 last_page_mouse_down_ = page_index; |
| 1343 double page_x, page_y; | 1671 double page_x, page_y; |
| 1344 pp::Point point = event.GetPosition(); | 1672 pp::Point point = event.GetPosition(); |
| 1345 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1673 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1346 | 1674 |
| 1347 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1675 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1348 int control = FPDPage_HasFormFieldAtPoint( | 1676 int control = FPDPage_HasFormFieldAtPoint( |
| 1349 form_, pages_[page_index]->GetPage(), page_x, page_y); | 1677 form_, pages_[page_index]->GetPage(), page_x, page_y); |
| 1350 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... | 1678 if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
| 1679 #ifdef _TEST_XFA_ | |
| 1351 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || | 1680 client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| 1352 control == FPDF_FORMFIELD_COMBOBOX); | 1681 control == FPDF_FORMFIELD_COMBOBOX || |
| 1682 » » control == FPDF_FORMFIELD_XFA); | |
| 1683 #else | |
| 1684 » » client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXT FIELD || | |
| 1685 » » » control == FPDF_FORMFIELD_COMBOBOX); | |
| 1686 #endif | |
| 1353 return true; // Return now before we get into the selection code. | 1687 return true; // Return now before we get into the selection code. |
| 1354 } | 1688 } |
| 1355 } | 1689 } |
| 1356 | 1690 |
| 1357 client_->FormTextFieldFocusChange(false); | 1691 client_->FormTextFieldFocusChange(false); |
| 1358 | 1692 |
| 1359 if (area != PDFiumPage::TEXT_AREA) | 1693 if (area != PDFiumPage::TEXT_AREA) |
| 1360 return true; // Return true so WebKit doesn't do its own highlighting. | 1694 return true; // Return true so WebKit doesn't do its own highlighting. |
| 1361 | 1695 |
| 1362 if (event.GetClickCount() == 1) { | 1696 if (event.GetClickCount() == 1) { |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2227 if (!form_) { | 2561 if (!form_) { |
| 2228 // Only returns 0 when data isn't available. If form data is downloaded, or | 2562 // Only returns 0 when data isn't available. If form data is downloaded, or |
| 2229 // if this isn't a form, returns positive values. | 2563 // if this isn't a form, returns positive values. |
| 2230 if (!doc_loader_.IsDocumentComplete() && | 2564 if (!doc_loader_.IsDocumentComplete() && |
| 2231 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { | 2565 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { |
| 2232 return; | 2566 return; |
| 2233 } | 2567 } |
| 2234 | 2568 |
| 2235 form_ = FPDFDOC_InitFormFillEnviroument( | 2569 form_ = FPDFDOC_InitFormFillEnviroument( |
| 2236 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); | 2570 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); |
| 2571 #ifdef _TEST_XFA_ | |
| 2572 FPDF_LoadXFA(doc_); | |
| 2573 #endif | |
| 2574 | |
| 2237 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); | 2575 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); |
| 2238 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); | 2576 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); |
| 2239 } | 2577 } |
| 2240 | 2578 |
| 2241 if (!doc_loader_.IsDocumentComplete()) { | 2579 if (!doc_loader_.IsDocumentComplete()) { |
| 2242 // Check if the first page is available. In a linearized PDF, that is not | 2580 // 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 | 2581 // 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. | 2582 // document is available, the first page is available as well. |
| 2245 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); | 2583 CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_); |
| 2246 } | 2584 } |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3536 double* height) { | 3874 double* height) { |
| 3537 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3875 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3538 if (!doc) | 3876 if (!doc) |
| 3539 return false; | 3877 return false; |
| 3540 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3878 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3541 FPDF_CloseDocument(doc); | 3879 FPDF_CloseDocument(doc); |
| 3542 return success; | 3880 return success; |
| 3543 } | 3881 } |
| 3544 | 3882 |
| 3545 } // namespace chrome_pdf | 3883 } // namespace chrome_pdf |
| OLD | NEW |