Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index 9fb2b7e099bdad4d6829792039df90c94d250e2e..b17a52a53ea7f9ca982f2f283d57d60850d3f7e3 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -614,7 +614,26 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) |
| FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; |
| FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; |
| FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; |
| - |
| +#ifdef _TEST_XFA_ |
| + FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; |
| + FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; |
| + //FPDF_FORMFILLINFO::FFI_GetCurDocumentIndex = Form_GetCurDocumentIndex; |
| + //FPDF_FORMFILLINFO::FFI_GetDocumentCount = Form_GetDocumentCount; |
| + FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; |
| + FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; |
| + FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; |
| + FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; |
| + FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; |
| + FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; |
| + FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; |
| +// FPDF_FORMFILLINFO::FFI_ShowFileDialog = Form_ShowFileDialog; |
| + FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; |
| + FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; |
| + // FPDF_FORMFILLINFO::FFI_GetFilePath = MyForm_GetFilePath; |
| + FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; |
| + FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; |
| + FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; |
| +#endif // _TEST_XFA_ |
| IPDF_JSPLATFORM::version = 1; |
| IPDF_JSPLATFORM::app_alert = Form_Alert; |
| IPDF_JSPLATFORM::app_beep = Form_Beep; |
| @@ -638,9 +657,11 @@ PDFiumEngine::~PDFiumEngine() { |
| if (doc_) { |
| if (form_) { |
| FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| - FPDFDOC_ExitFormFillEnviroument(form_); |
| } |
| FPDF_CloseDocument(doc_); |
| + if (form_) { |
| + FPDFDOC_ExitFormFillEnviroument(form_); |
| + } |
| } |
| if (fpdf_availability_) |
| @@ -649,6 +670,313 @@ PDFiumEngine::~PDFiumEngine() { |
| STLDeleteElements(&pages_); |
| } |
| +#ifdef _TEST_XFA_ |
| + |
| +typedef struct _FPDF_FILE { |
| + FPDF_FILEHANDLER fileHandler; |
| + FILE* file; |
| +}FPDF_FILE; |
| + |
| + |
| +void Sample_Release(FPDF_LPVOID clientData) { |
| + 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.
|
| + |
| + fclose(((FPDF_FILE*)clientData)->file); |
| + delete ((FPDF_FILE*)clientData); |
| +} |
| + |
| +FPDF_DWORD Sample_GetSize(FPDF_LPVOID clientData) { |
| + if (!clientData) return 0; |
| + |
| + long curPos = ftell(((FPDF_FILE*)clientData)->file); |
| + fseek(((FPDF_FILE*)clientData)->file, 0, SEEK_END); |
| + long size = ftell(((FPDF_FILE*)clientData)->file); |
| + fseek(((FPDF_FILE*)clientData)->file, curPos, SEEK_SET); |
| + |
| + return (FPDF_DWORD)size; |
| +} |
| + |
| +FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPVOID buffer, FPDF_DWORD size) { |
| + if (!clientData) return -1; |
| + |
| + fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET); |
| + size_t readSize = fread(buffer, 1, size, ((FPDF_FILE*)clientData)->file); |
| + return readSize == size ? 0 : -1; |
| +} |
| + |
| +FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPCVOID buffer, FPDF_DWORD size) { |
| + if (!clientData) return -1; |
| + |
| + fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET); |
| + //Write data |
| + size_t writeSize = fwrite(buffer, 1, size, ((FPDF_FILE*)clientData)->file); |
| + return writeSize == size ? 0 : -1; |
| +} |
| + |
| +FPDF_RESULT Sample_Flush(FPDF_LPVOID clientData) { |
| + if (!clientData) return -1; |
| + |
| + //Flush file |
| + fflush(((FPDF_FILE*)clientData)->file); |
| + |
| + return 0; |
| +} |
| + |
| +FPDF_RESULT Sample_Truncate(FPDF_LPVOID clientData, FPDF_DWORD size) { |
| + return 0; |
| +} |
| + |
| + |
| +void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* pThis, |
| + FPDF_FILEHANDLER* fileHandler, |
| + FPDF_WIDESTRING to, |
| + FPDF_WIDESTRING subject, |
| + FPDF_WIDESTRING cc, |
| + FPDF_WIDESTRING bcc, |
| + FPDF_WIDESTRING message) { |
| + std::string to_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| + std::string subject_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject)); |
| + std::string cc_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc)); |
| + std::string bcc_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc)); |
| + std::string message_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message)); |
| + |
| + PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| + engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str); |
| +} |
| + |
| +void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* pThis, |
| + FPDF_PAGE page, FPDF_BOOL bVisible, |
| + double left, double top, double right, double bottom) { |
| + PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| + engine->client_->UpdateCursor(PP_CURSORTYPE_IBEAM); |
| + std::vector<pp::Rect> tickmarks; |
| + pp::Rect rect(left, top, right, bottom); |
| + tickmarks.push_back(rect); |
| + engine->client_->UpdateTickMarks(tickmarks); |
| +} |
| + |
| +//int PDFiumEngine::Form_GetCurDocumentIndex(FPDF_FORMFILLINFO* pThis) { |
| +// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| +// engine->client_->RunJSCmd("alert(\"GetCurDocumentIndex\")"); |
| +// return 0; |
| +//} |
| +// |
| +//int PDFiumEngine::Form_GetDocumentCount(FPDF_FORMFILLINFO* pThis) { |
| +// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| +// engine->client_->RunJSCmd("alert(\"GetCurDocumentCount\")"); |
| +// return 0; |
| +//} |
| + |
| +void PDFiumEngine::Form_SetCurrentPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, int iCurPage) { |
| + PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| + pp::Rect pageViewRect = engine->GetPageContentsRect(iCurPage); |
| + engine->ScrolledToYPosition(pageViewRect.height()); |
| + pp::Point pos(1, pageViewRect.height()); |
| + engine->SetScrollPosition(pos); |
| +} |
| + |
| +int PDFiumEngine::Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document) { |
| + //int pageCount = FPDF_GetPageCount(document); |
| + int pageIndex = -1; |
| + PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| + pageIndex = engine->GetMostVisiblePage(); |
| + return pageIndex; |
| +} |
| + |
| +void PDFiumEngine::Form_GetPageViewRect(FPDF_FORMFILLINFO* pThis, |
| + FPDF_PAGE page, |
| + double* left, double* top, double* right, double* bottom) { |
| + PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| + int page_index = engine->GetMostVisiblePage(); |
| + pp::Rect pageViewRect = engine->GetPageContentsRect(page_index); |
| + |
| + *left = pageViewRect.x(); |
| + *right = pageViewRect.width() + pageViewRect.x(); |
| + *top = pageViewRect.y(); |
| + *bottom = pageViewRect.height(); |
| + |
| + std::string javascript = "alert(\"PageViewRect:" |
| + + base::DoubleToString(*left) + "," |
| + + base::DoubleToString(*right) + "," |
| + + base::DoubleToString(*top) + "," |
| + + base::DoubleToString(*bottom) + "," |
| + + "\")"; |
| + |
| +} |
| + |
| +int PDFiumEngine::Form_GetPlatform(FPDF_FORMFILLINFO* pThis, |
| + void* platform, |
| + int length) { |
| + int platform_flag = -1; |
| +#if defined(WIN32) |
| + platform_flag = 0; |
| +#elif defined(__linux__) |
| + platform_flag = 1; |
| +#else |
| + platform_flag = 2; |
| +#endif |
| + std::string javascript = "alert(\"Platform:" |
| + + base::DoubleToString(platform_flag) |
| + + "\")"; |
| + //platform = new char[3]; |
| + //char tem[10] = "WIN"; |
| + //strncpy((char*)platform, tem, 3); |
| + |
| + return 3; |
| +} |
| + |
| +FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* pThis, |
| + FPDF_PAGE page, |
| + FPDF_WIDGET hWidget, |
| + int menuFlag, float x, float y) { |
| + return false; |
| +} |
| + |
| +FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, |
| + FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsContentType, |
| + FPDF_WIDESTRING wsEncode, FPDF_WIDESTRING wsHeader, FPDF_BSTR* respone) { |
| + std::string url_str = |
| + 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
|
| + std::string data_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData)); |
| + std::string content_type_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsContentType)); |
| + std::string encode_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode)); |
| + std::string header_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsHeader)); |
| + |
| + std::string javascript = "alert(\"Post:" |
| + + url_str + "," + data_str + "," + content_type_str + "," |
| + + encode_str + "," + header_str |
| + + "\")"; |
| + return true; |
| +} |
| + |
| +FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* pThis, |
| + FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsEncode) { |
| + std::string url_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); |
| + std::string data_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData)); |
| + std::string encode_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode)); |
| + |
| + std::string javascript = "alert(\"Put:" |
| + + url_str + "," + data_str + "," + encode_str |
| + + "\")"; |
| + |
| + return true; |
| +} |
| + |
| +//FPDF_BOOL PDFiumEngine::Form_ShowFileDialog(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE pathArr) { |
| +// int tem = 1; |
| +// tem++; |
| +// return false; |
| +//} |
| + |
| +void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo) { |
| + std::string to_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(uploadTo)); |
| + |
| +} |
| + |
| +FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL) { |
| + std::string url_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(URL)); |
| + |
| + |
| + // Get URL data... |
| + FILE* file = fopen(XFA_TESTFILE("downloadtest.tem"), "w"); |
| + FPDF_FILE* pFileHander = new FPDF_FILE; |
| + pFileHander->file = file; |
| + pFileHander->fileHandler.clientData = pFileHander; |
| + pFileHander->fileHandler.Flush = Sample_Flush; |
| + pFileHander->fileHandler.GetSize = Sample_GetSize; |
| + pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; |
| + pFileHander->fileHandler.Release = Sample_Release; |
| + pFileHander->fileHandler.Truncate = Sample_Truncate; |
| + pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; |
| + |
| + return &pFileHander->fileHandler; |
| +} |
| + |
| +//FPDF_BOOL PDFiumEngine::MyForm_GetFilePath(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* pFileHandler, void* filePath, int length) { |
| +// //std::string filePath = engine->client_->FileOpen(fileFlag); |
| +// if (filePath == NULL) { |
| +// std::string javascript = "alert(\"GetFilePath:NULL\")"; |
| +// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| +// engine->client_->RunJSCmd(javascript); |
| +// return false; |
| +// } |
| +// std::string filePath_str = (char*)filePath; |
| +// |
| +// std::string javascript = "alert(\"GetFilePath:" + filePath_str + "\")"; |
| +// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis); |
| +// engine->client_->RunJSCmd(javascript); |
| +// |
| +// FILE* file = fopen(FXQA_TESTFILE("tem.xdp"), "w"); |
| +// FPDF_FILE* pFileHander = new FPDF_FILE; |
| +// pFileHander->file = file; |
| +// pFileHander->fileHandler.clientData = pFileHander; |
| +// pFileHander->fileHandler.Flush = Sample_Flush; |
| +// pFileHander->fileHandler.GetSize = Sample_GetSize; |
| +// pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; |
| +// pFileHander->fileHandler.Release = Sample_Release; |
| +// pFileHander->fileHandler.Truncate = Sample_Truncate; |
| +// pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; |
| +// |
| +// pFileHandler = &pFileHander->fileHandler; |
| +// |
| +// return true; |
| +//} |
| + |
| +FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* pThis, int fileFlag, FPDF_WIDESTRING wsURL, const char* mode) { |
| + std::string url_str = "NULL"; |
| + if (wsURL == NULL) { |
| + url_str = "NULL"; |
|
Lei Zhang
2014/11/05 22:45:09
It's already initialized to "NULL"
|
| + } |
| + else { |
| + url_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); |
| + } |
| + if (strncmp(mode, "wb", 2) == 0) { |
| + |
| + FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); |
| + FPDF_FILE* pFileHander = new FPDF_FILE; |
| + pFileHander->file = file; |
| + pFileHander->fileHandler.clientData = pFileHander; |
| + pFileHander->fileHandler.Flush = Sample_Flush; |
| + pFileHander->fileHandler.GetSize = Sample_GetSize; |
| + pFileHander->fileHandler.ReadBlock = Sample_ReadBlock; |
| + pFileHander->fileHandler.Release = Sample_Release; |
| + pFileHander->fileHandler.Truncate = Sample_Truncate; |
| + pFileHander->fileHandler.WriteBlock = Sample_WriteBlock; |
| + return &pFileHander->fileHandler; |
| + } |
| + else { |
| + url_str = base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); |
| + } |
| + return NULL; |
| +} |
| + |
| + |
| +void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDESTRING wsURL) { |
| + std::string url_str = |
| + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL)); |
| +} |
| + |
| +int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* pThis, void* language, int length) { |
| + return 0; |
| +} |
| + |
| +#endif // _TEST_XFA_ |
| + |
| int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| unsigned char* buffer, unsigned long size) { |
| DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| @@ -921,7 +1249,7 @@ void PDFiumEngine::UnsupportedFeature(int type) { |
| std::string feature; |
| switch (type) { |
| case FPDF_UNSP_DOC_XFAFORM: |
| - feature = "XFA"; |
| + //feature = "XFA"; |
| break; |
| case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| feature = "Portfolios_Packages"; |
| @@ -1348,8 +1676,14 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
| int control = FPDPage_HasFormFieldAtPoint( |
| form_, pages_[page_index]->GetPage(), page_x, page_y); |
| if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... |
| +#ifdef _TEST_XFA_ |
| client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| - control == FPDF_FORMFIELD_COMBOBOX); |
| + control == FPDF_FORMFIELD_COMBOBOX || |
| + control == FPDF_FORMFIELD_XFA); |
| +#else |
| + client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| + control == FPDF_FORMFIELD_COMBOBOX); |
| +#endif |
| return true; // Return now before we get into the selection code. |
| } |
| } |
| @@ -2234,6 +2568,10 @@ void PDFiumEngine::ContinueLoadingDocument( |
| form_ = FPDFDOC_InitFormFillEnviroument( |
| doc_, static_cast<FPDF_FORMFILLINFO*>(this)); |
| +#ifdef _TEST_XFA_ |
| + FPDF_LoadXFA(doc_); |
| +#endif |
| + |
| FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); |
| FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); |
| } |