| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 FPDF_GetMetaText(doc, key.c_str(), string_adapter.GetData(), size)); | 587 FPDF_GetMetaText(doc, key.c_str(), string_adapter.GetData(), size)); |
| 588 return base::UTF16ToUTF8(value); | 588 return base::UTF16ToUTF8(value); |
| 589 } | 589 } |
| 590 | 590 |
| 591 gin::IsolateHolder* g_isolate_holder = nullptr; | 591 gin::IsolateHolder* g_isolate_holder = nullptr; |
| 592 | 592 |
| 593 void SetUpV8() { | 593 void SetUpV8() { |
| 594 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 594 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
| 595 gin::IsolateHolder::kStableV8Extras, | 595 gin::IsolateHolder::kStableV8Extras, |
| 596 gin::ArrayBufferAllocator::SharedInstance()); | 596 gin::ArrayBufferAllocator::SharedInstance()); |
| 597 DCHECK(!g_isolate_holder); |
| 597 g_isolate_holder = new gin::IsolateHolder(base::ThreadTaskRunnerHandle::Get(), | 598 g_isolate_holder = new gin::IsolateHolder(base::ThreadTaskRunnerHandle::Get(), |
| 598 gin::IsolateHolder::kSingleThread); | 599 gin::IsolateHolder::kSingleThread); |
| 599 g_isolate_holder->isolate()->Enter(); | 600 g_isolate_holder->isolate()->Enter(); |
| 600 } | 601 } |
| 601 | 602 |
| 602 void TearDownV8() { | 603 void TearDownV8() { |
| 603 g_isolate_holder->isolate()->Exit(); | 604 g_isolate_holder->isolate()->Exit(); |
| 604 delete g_isolate_holder; | 605 delete g_isolate_holder; |
| 605 g_isolate_holder = nullptr; | 606 g_isolate_holder = nullptr; |
| 606 } | 607 } |
| 607 | 608 |
| 608 int GetBlockForJpeg(void* param, | 609 int GetBlockForJpeg(void* param, |
| 609 unsigned long pos, | 610 unsigned long pos, |
| 610 unsigned char* buf, | 611 unsigned char* buf, |
| 611 unsigned long size) { | 612 unsigned long size) { |
| 612 std::vector<uint8_t>* data_vector = static_cast<std::vector<uint8_t>*>(param); | 613 std::vector<uint8_t>* data_vector = static_cast<std::vector<uint8_t>*>(param); |
| 613 if (pos + size < pos || pos + size > data_vector->size()) | 614 if (pos + size < pos || pos + size > data_vector->size()) |
| 614 return 0; | 615 return 0; |
| 615 memcpy(buf, data_vector->data() + pos, size); | 616 memcpy(buf, data_vector->data() + pos, size); |
| 616 return 1; | 617 return 1; |
| 617 } | 618 } |
| 618 | 619 |
| 620 std::string WideStringToString(FPDF_WIDESTRING wide_string) { |
| 621 return base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wide_string)); |
| 622 } |
| 623 |
| 619 } // namespace | 624 } // namespace |
| 620 | 625 |
| 621 bool InitializeSDK() { | 626 bool InitializeSDK() { |
| 622 SetUpV8(); | 627 SetUpV8(); |
| 623 | 628 |
| 624 FPDF_LIBRARY_CONFIG config; | 629 FPDF_LIBRARY_CONFIG config; |
| 625 config.version = 2; | 630 config.version = 2; |
| 626 config.m_pUserFontPaths = nullptr; | 631 config.m_pUserFontPaths = nullptr; |
| 627 config.m_pIsolate = v8::Isolate::GetCurrent(); | 632 config.m_pIsolate = v8::Isolate::GetCurrent(); |
| 628 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; | 633 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 793 |
| 789 #if defined(PDF_ENABLE_XFA) | 794 #if defined(PDF_ENABLE_XFA) |
| 790 | 795 |
| 791 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, | 796 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, |
| 792 FPDF_FILEHANDLER* file_handler, | 797 FPDF_FILEHANDLER* file_handler, |
| 793 FPDF_WIDESTRING to, | 798 FPDF_WIDESTRING to, |
| 794 FPDF_WIDESTRING subject, | 799 FPDF_WIDESTRING subject, |
| 795 FPDF_WIDESTRING cc, | 800 FPDF_WIDESTRING cc, |
| 796 FPDF_WIDESTRING bcc, | 801 FPDF_WIDESTRING bcc, |
| 797 FPDF_WIDESTRING message) { | 802 FPDF_WIDESTRING message) { |
| 798 std::string to_str = | 803 std::string to_str = WideStringToString(to); |
| 799 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 804 std::string subject_str = WideStringToString(subject); |
| 800 std::string subject_str = | 805 std::string cc_str = WideStringToString(cc); |
| 801 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); | 806 std::string bcc_str = WideStringToString(bcc); |
| 802 std::string cc_str = | 807 std::string message_str = WideStringToString(message); |
| 803 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); | |
| 804 std::string bcc_str = | |
| 805 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); | |
| 806 std::string message_str = | |
| 807 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | |
| 808 | 808 |
| 809 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 809 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 810 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); | 810 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); |
| 811 } | 811 } |
| 812 | 812 |
| 813 void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* param, | 813 void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* param, |
| 814 FPDF_PAGE page, | 814 FPDF_PAGE page, |
| 815 FPDF_BOOL visible, | 815 FPDF_BOOL visible, |
| 816 double left, | 816 double left, |
| 817 double top, | 817 double top, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 return false; | 885 return false; |
| 886 } | 886 } |
| 887 | 887 |
| 888 FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* param, | 888 FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* param, |
| 889 FPDF_WIDESTRING url, | 889 FPDF_WIDESTRING url, |
| 890 FPDF_WIDESTRING data, | 890 FPDF_WIDESTRING data, |
| 891 FPDF_WIDESTRING content_type, | 891 FPDF_WIDESTRING content_type, |
| 892 FPDF_WIDESTRING encode, | 892 FPDF_WIDESTRING encode, |
| 893 FPDF_WIDESTRING header, | 893 FPDF_WIDESTRING header, |
| 894 FPDF_BSTR* response) { | 894 FPDF_BSTR* response) { |
| 895 std::string url_str = | 895 std::string url_str = WideStringToString(url); |
| 896 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 896 std::string data_str = WideStringToString(data); |
| 897 std::string data_str = | 897 std::string content_type_str = WideStringToString(content_type); |
| 898 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | 898 std::string encode_str = WideStringToString(encode); |
| 899 std::string content_type_str = | 899 std::string header_str = WideStringToString(header); |
| 900 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(content_type)); | |
| 901 std::string encode_str = | |
| 902 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | |
| 903 std::string header_str = | |
| 904 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(header)); | |
| 905 | 900 |
| 906 std::string javascript = "alert(\"Post:" + url_str + "," + data_str + "," + | 901 std::string javascript = "alert(\"Post:" + url_str + "," + data_str + "," + |
| 907 content_type_str + "," + encode_str + "," + | 902 content_type_str + "," + encode_str + "," + |
| 908 header_str + "\")"; | 903 header_str + "\")"; |
| 909 return true; | 904 return true; |
| 910 } | 905 } |
| 911 | 906 |
| 912 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* param, | 907 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* param, |
| 913 FPDF_WIDESTRING url, | 908 FPDF_WIDESTRING url, |
| 914 FPDF_WIDESTRING data, | 909 FPDF_WIDESTRING data, |
| 915 FPDF_WIDESTRING encode) { | 910 FPDF_WIDESTRING encode) { |
| 916 std::string url_str = | 911 std::string url_str = WideStringToString(url); |
| 917 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 912 std::string data_str = WideStringToString(data); |
| 918 std::string data_str = | 913 std::string encode_str = WideStringToString(encode); |
| 919 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | |
| 920 std::string encode_str = | |
| 921 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | |
| 922 | 914 |
| 923 std::string javascript = | 915 std::string javascript = |
| 924 "alert(\"Put:" + url_str + "," + data_str + "," + encode_str + "\")"; | 916 "alert(\"Put:" + url_str + "," + data_str + "," + encode_str + "\")"; |
| 925 | 917 |
| 926 return true; | 918 return true; |
| 927 } | 919 } |
| 928 | 920 |
| 929 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* param, | 921 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* param, |
| 930 FPDF_FILEHANDLER* file_handle, | 922 FPDF_FILEHANDLER* file_handle, |
| 931 int file_flag, | 923 int file_flag, |
| 932 FPDF_WIDESTRING to) { | 924 FPDF_WIDESTRING to) { |
| 933 std::string to_str = | 925 std::string to_str = WideStringToString(to); |
| 934 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | |
| 935 // TODO: needs the full implementation of form uploading | 926 // TODO: needs the full implementation of form uploading |
| 936 } | 927 } |
| 937 | 928 |
| 938 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, | 929 FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* param, |
| 939 FPDF_WIDESTRING url) { | 930 FPDF_WIDESTRING url) { |
| 940 // NOTE: Think hard about the security implications before allowing | 931 // NOTE: Think hard about the security implications before allowing |
| 941 // a PDF file to perform this action. | 932 // a PDF file to perform this action. |
| 942 return nullptr; | 933 return nullptr; |
| 943 } | 934 } |
| 944 | 935 |
| 945 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, | 936 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, |
| 946 int file_flag, | 937 int file_flag, |
| 947 FPDF_WIDESTRING url, | 938 FPDF_WIDESTRING url, |
| 948 const char* mode) { | 939 const char* mode) { |
| 949 // NOTE: Think hard about the security implications before allowing | 940 // NOTE: Think hard about the security implications before allowing |
| 950 // a PDF file to perform this action. | 941 // a PDF file to perform this action. |
| 951 return nullptr; | 942 return nullptr; |
| 952 } | 943 } |
| 953 | 944 |
| 954 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, | 945 void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* param, |
| 955 FPDF_DOCUMENT document, | 946 FPDF_DOCUMENT document, |
| 956 FPDF_WIDESTRING url) { | 947 FPDF_WIDESTRING url) { |
| 957 std::string url_str = | 948 std::string url_str = WideStringToString(url); |
| 958 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 959 // TODO: needs to implement GOTO URL action | 949 // TODO: needs to implement GOTO URL action |
| 960 } | 950 } |
| 961 | 951 |
| 962 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, | 952 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, |
| 963 void* language, | 953 void* language, |
| 964 int length) { | 954 int length) { |
| 965 return 0; | 955 return 0; |
| 966 } | 956 } |
| 967 | 957 |
| 968 #endif // defined(PDF_ENABLE_XFA) | 958 #endif // defined(PDF_ENABLE_XFA) |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 } | 1350 } |
| 1361 | 1351 |
| 1362 pp::Resource PDFiumEngine::PrintPages( | 1352 pp::Resource PDFiumEngine::PrintPages( |
| 1363 const PP_PrintPageNumberRange_Dev* page_ranges, | 1353 const PP_PrintPageNumberRange_Dev* page_ranges, |
| 1364 uint32_t page_range_count, | 1354 uint32_t page_range_count, |
| 1365 const PP_PrintSettings_Dev& print_settings) { | 1355 const PP_PrintSettings_Dev& print_settings) { |
| 1366 ScopedSubstFont scoped_subst_font(this); | 1356 ScopedSubstFont scoped_subst_font(this); |
| 1367 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY) && | 1357 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY) && |
| 1368 (print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) { | 1358 (print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) { |
| 1369 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); | 1359 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); |
| 1370 } else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) { | 1360 } |
| 1361 if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) |
| 1371 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); | 1362 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); |
| 1372 } | |
| 1373 | |
| 1374 return pp::Resource(); | 1363 return pp::Resource(); |
| 1375 } | 1364 } |
| 1376 | 1365 |
| 1377 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf( | 1366 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf( |
| 1378 double source_page_width, | 1367 double source_page_width, |
| 1379 double source_page_height, | 1368 double source_page_height, |
| 1380 const PP_PrintSettings_Dev& print_settings, | 1369 const PP_PrintSettings_Dev& print_settings, |
| 1381 PDFiumPage* page_to_print) { | 1370 PDFiumPage* page_to_print) { |
| 1382 FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument(); | 1371 FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument(); |
| 1383 if (!temp_doc) | 1372 if (!temp_doc) |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 | 2187 |
| 2199 // Move back/forward through the search locations we previously found. | 2188 // Move back/forward through the search locations we previously found. |
| 2200 size_t new_index; | 2189 size_t new_index; |
| 2201 const size_t last_index = find_results_.size() - 1; | 2190 const size_t last_index = find_results_.size() - 1; |
| 2202 | 2191 |
| 2203 if (resume_find_index_.valid()) { | 2192 if (resume_find_index_.valid()) { |
| 2204 new_index = resume_find_index_.GetIndex(); | 2193 new_index = resume_find_index_.GetIndex(); |
| 2205 resume_find_index_.Invalidate(); | 2194 resume_find_index_.Invalidate(); |
| 2206 } else if (current_find_index_.valid()) { | 2195 } else if (current_find_index_.valid()) { |
| 2207 size_t current_index = current_find_index_.GetIndex(); | 2196 size_t current_index = current_find_index_.GetIndex(); |
| 2208 if (forward) { | 2197 if ((forward && current_index >= last_index) || |
| 2209 if (current_index >= last_index) { | 2198 (!forward && current_index == 0)) { |
| 2210 current_find_index_.Invalidate(); | 2199 current_find_index_.Invalidate(); |
| 2211 client_->NotifySelectedFindResultChanged(-1); | 2200 client_->NotifySelectedFindResultChanged(-1); |
| 2212 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); | 2201 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); |
| 2213 return true; | 2202 return true; |
| 2214 } | |
| 2215 new_index = current_index + 1; | |
| 2216 } else { | |
| 2217 if (current_find_index_.GetIndex() == 0) { | |
| 2218 current_find_index_.Invalidate(); | |
| 2219 client_->NotifySelectedFindResultChanged(-1); | |
| 2220 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); | |
| 2221 return true; | |
| 2222 } | |
| 2223 new_index = current_index - 1; | |
| 2224 } | 2203 } |
| 2204 int increment = forward ? 1 : -1; |
| 2205 new_index = current_index + increment; |
| 2225 } else { | 2206 } else { |
| 2226 new_index = forward ? 0 : last_index; | 2207 new_index = forward ? 0 : last_index; |
| 2227 } | 2208 } |
| 2228 current_find_index_.SetIndex(new_index); | 2209 current_find_index_.SetIndex(new_index); |
| 2229 | 2210 |
| 2230 // Update the selection before telling the client to scroll, since it could | 2211 // Update the selection before telling the client to scroll, since it could |
| 2231 // paint then. | 2212 // paint then. |
| 2232 selection_.clear(); | 2213 selection_.clear(); |
| 2233 selection_.push_back(find_results_[current_find_index_.GetIndex()]); | 2214 selection_.push_back(find_results_[current_find_index_.GetIndex()]); |
| 2234 | 2215 |
| (...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3723 }; | 3704 }; |
| 3724 | 3705 |
| 3725 enum AlertResult { | 3706 enum AlertResult { |
| 3726 ALERT_RESULT_OK = 1, | 3707 ALERT_RESULT_OK = 1, |
| 3727 ALERT_RESULT_CANCEL, | 3708 ALERT_RESULT_CANCEL, |
| 3728 ALERT_RESULT_NO, | 3709 ALERT_RESULT_NO, |
| 3729 ALERT_RESULT_YES | 3710 ALERT_RESULT_YES |
| 3730 }; | 3711 }; |
| 3731 | 3712 |
| 3732 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3713 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3733 std::string message_str = | 3714 std::string message_str = WideStringToString(message); |
| 3734 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | |
| 3735 if (type == ALERT_TYPE_OK) { | 3715 if (type == ALERT_TYPE_OK) { |
| 3736 engine->client_->Alert(message_str); | 3716 engine->client_->Alert(message_str); |
| 3737 return ALERT_RESULT_OK; | 3717 return ALERT_RESULT_OK; |
| 3738 } | 3718 } |
| 3739 | 3719 |
| 3740 bool rv = engine->client_->Confirm(message_str); | 3720 bool rv = engine->client_->Confirm(message_str); |
| 3741 if (type == ALERT_TYPE_OK_CANCEL) | 3721 if (type == ALERT_TYPE_OK_CANCEL) |
| 3742 return rv ? ALERT_RESULT_OK : ALERT_RESULT_CANCEL; | 3722 return rv ? ALERT_RESULT_OK : ALERT_RESULT_CANCEL; |
| 3743 return rv ? ALERT_RESULT_YES : ALERT_RESULT_NO; | 3723 return rv ? ALERT_RESULT_YES : ALERT_RESULT_NO; |
| 3744 } | 3724 } |
| 3745 | 3725 |
| 3746 void PDFiumEngine::Form_Beep(IPDF_JSPLATFORM* param, int type) { | 3726 void PDFiumEngine::Form_Beep(IPDF_JSPLATFORM* param, int type) { |
| 3747 // Beeps are annoying, and not possible using javascript, so ignore for now. | 3727 // Beeps are annoying, and not possible using javascript, so ignore for now. |
| 3748 } | 3728 } |
| 3749 | 3729 |
| 3750 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, | 3730 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, |
| 3751 FPDF_WIDESTRING question, | 3731 FPDF_WIDESTRING question, |
| 3752 FPDF_WIDESTRING title, | 3732 FPDF_WIDESTRING title, |
| 3753 FPDF_WIDESTRING default_response, | 3733 FPDF_WIDESTRING default_response, |
| 3754 FPDF_WIDESTRING label, | 3734 FPDF_WIDESTRING label, |
| 3755 FPDF_BOOL password, | 3735 FPDF_BOOL password, |
| 3756 void* response, | 3736 void* response, |
| 3757 int length) { | 3737 int length) { |
| 3758 std::string question_str = | 3738 std::string question_str = WideStringToString(question); |
| 3759 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(question)); | 3739 std::string default_str = WideStringToString(default_response); |
| 3760 std::string default_str = base::UTF16ToUTF8( | |
| 3761 reinterpret_cast<const base::char16*>(default_response)); | |
| 3762 | 3740 |
| 3763 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3741 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3764 std::string rv = engine->client_->Prompt(question_str, default_str); | 3742 std::string rv = engine->client_->Prompt(question_str, default_str); |
| 3765 base::string16 rv_16 = base::UTF8ToUTF16(rv); | 3743 base::string16 rv_16 = base::UTF8ToUTF16(rv); |
| 3766 int rv_bytes = rv_16.size() * sizeof(base::char16); | 3744 int rv_bytes = rv_16.size() * sizeof(base::char16); |
| 3767 if (response) { | 3745 if (response) { |
| 3768 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; | 3746 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; |
| 3769 memcpy(response, rv_16.c_str(), bytes_to_copy); | 3747 memcpy(response, rv_16.c_str(), bytes_to_copy); |
| 3770 } | 3748 } |
| 3771 return rv_bytes; | 3749 return rv_bytes; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3785 void* mail_data, | 3763 void* mail_data, |
| 3786 int length, | 3764 int length, |
| 3787 FPDF_BOOL ui, | 3765 FPDF_BOOL ui, |
| 3788 FPDF_WIDESTRING to, | 3766 FPDF_WIDESTRING to, |
| 3789 FPDF_WIDESTRING subject, | 3767 FPDF_WIDESTRING subject, |
| 3790 FPDF_WIDESTRING cc, | 3768 FPDF_WIDESTRING cc, |
| 3791 FPDF_WIDESTRING bcc, | 3769 FPDF_WIDESTRING bcc, |
| 3792 FPDF_WIDESTRING message) { | 3770 FPDF_WIDESTRING message) { |
| 3793 // Note: |mail_data| and |length| are ignored. We don't handle attachments; | 3771 // Note: |mail_data| and |length| are ignored. We don't handle attachments; |
| 3794 // there is no way with mailto. | 3772 // there is no way with mailto. |
| 3795 std::string to_str = | 3773 std::string to_str = WideStringToString(to); |
| 3796 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 3774 std::string cc_str = WideStringToString(cc); |
| 3797 std::string cc_str = | 3775 std::string bcc_str = WideStringToString(bcc); |
| 3798 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); | 3776 std::string subject_str = WideStringToString(subject); |
| 3799 std::string bcc_str = | 3777 std::string message_str = WideStringToString(message); |
| 3800 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); | |
| 3801 std::string subject_str = | |
| 3802 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); | |
| 3803 std::string message_str = | |
| 3804 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); | |
| 3805 | 3778 |
| 3806 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3779 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3807 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); | 3780 engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); |
| 3808 } | 3781 } |
| 3809 | 3782 |
| 3810 void PDFiumEngine::Form_Print(IPDF_JSPLATFORM* param, | 3783 void PDFiumEngine::Form_Print(IPDF_JSPLATFORM* param, |
| 3811 FPDF_BOOL ui, | 3784 FPDF_BOOL ui, |
| 3812 int start, | 3785 int start, |
| 3813 int end, | 3786 int end, |
| 3814 FPDF_BOOL silent, | 3787 FPDF_BOOL silent, |
| 3815 FPDF_BOOL shrink_to_fit, | 3788 FPDF_BOOL shrink_to_fit, |
| 3816 FPDF_BOOL print_as_image, | 3789 FPDF_BOOL print_as_image, |
| 3817 FPDF_BOOL reverse, | 3790 FPDF_BOOL reverse, |
| 3818 FPDF_BOOL annotations) { | 3791 FPDF_BOOL annotations) { |
| 3819 // No way to pass the extra information to the print dialog using JavaScript. | 3792 // No way to pass the extra information to the print dialog using JavaScript. |
| 3820 // Just opening it is fine for now. | 3793 // Just opening it is fine for now. |
| 3821 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3794 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3822 engine->client_->Print(); | 3795 engine->client_->Print(); |
| 3823 } | 3796 } |
| 3824 | 3797 |
| 3825 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, | 3798 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, |
| 3826 void* form_data, | 3799 void* form_data, |
| 3827 int length, | 3800 int length, |
| 3828 FPDF_WIDESTRING url) { | 3801 FPDF_WIDESTRING url) { |
| 3829 std::string url_str = | 3802 std::string url_str = WideStringToString(url); |
| 3830 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
| 3831 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3803 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3832 engine->client_->SubmitForm(url_str, form_data, length); | 3804 engine->client_->SubmitForm(url_str, form_data, length); |
| 3833 } | 3805 } |
| 3834 | 3806 |
| 3835 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, int page_number) { | 3807 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, int page_number) { |
| 3836 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3808 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3837 engine->ScrollToPage(page_number); | 3809 engine->ScrollToPage(page_number); |
| 3838 } | 3810 } |
| 3839 | 3811 |
| 3840 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, | 3812 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4119 FPDF_DOCUMENT doc = | 4091 FPDF_DOCUMENT doc = |
| 4120 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4092 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4121 if (!doc) | 4093 if (!doc) |
| 4122 return false; | 4094 return false; |
| 4123 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4095 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4124 FPDF_CloseDocument(doc); | 4096 FPDF_CloseDocument(doc); |
| 4125 return success; | 4097 return success; |
| 4126 } | 4098 } |
| 4127 | 4099 |
| 4128 } // namespace chrome_pdf | 4100 } // namespace chrome_pdf |
| OLD | NEW |