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..75e0d0876ab5c766a6a83fac4c1c4375bffeab45 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -614,7 +614,22 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) |
| FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; |
| FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; |
| FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; |
| - |
| +#ifdef _PDF_USE_XFA_ |
| + FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; |
| + FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; |
| + 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_UploadTo = Form_UploadTo; |
| + FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; |
| + FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; |
| + FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; |
| + FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; |
| +#endif // _PDF_USE_XFA_ |
| IPDF_JSPLATFORM::version = 1; |
| IPDF_JSPLATFORM::app_alert = Form_Alert; |
| IPDF_JSPLATFORM::app_beep = Form_Beep; |
| @@ -638,9 +653,11 @@ PDFiumEngine::~PDFiumEngine() { |
| if (doc_) { |
| if (form_) { |
| FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
| - FPDFDOC_ExitFormFillEnviroument(form_); |
| } |
| FPDF_CloseDocument(doc_); |
| + if (form_) { |
| + FPDFDOC_ExitFormFillEnviroument(form_); |
|
Lei Zhang
2014/11/06 04:08:08
Can you explain why we have to do this after calli
Bo Xu
2014/11/06 05:43:51
XFA document is independent from PDF even it can b
Lei Zhang
2014/11/06 19:15:29
I just want to make sure it works with or without
|
| + } |
| } |
| if (fpdf_availability_) |
| @@ -649,6 +666,293 @@ PDFiumEngine::~PDFiumEngine() { |
| STLDeleteElements(&pages_); |
| } |
| +#ifdef _PDF_USE_XFA_ |
| + |
| +#if defined(WIN32) |
|
Lei Zhang
2014/11/06 04:08:08
Please add a comment to mention this is just here
|
| +#define XFA_TESTFILE(filename) "E:/"#filename |
| +#else |
| +#define XFA_TESTFILE(filename) "/home/"#filename |
| +#endif |
| + |
| +typedef struct _FPDF_FILE { |
|
Lei Zhang
2014/11/06 04:08:08
You can just declare struct FPDF_FILE { .. }; dire
|
| + FPDF_FILEHANDLER fileHandler; |
| + FILE* file; |
| +}FPDF_FILE; |
| + |
| +void Sample_Release(FPDF_LPVOID clientData) { |
| + if (!clientData) |
| + return; |
| + fclose(((FPDF_FILE*)clientData)->file); |
|
Lei Zhang
2014/11/06 04:08:08
Maybe just declare a new pointer and only cast |cl
|
| + 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 |
|
Lei Zhang
2014/11/06 04:08:08
nit: space after //
|
| + 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); |
| +} |
| + |
| +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 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]; |
|
Lei Zhang
2014/11/06 04:08:08
There's still some commented out code here.
|
| + //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) { |
|
Lei Zhang
2014/11/06 04:08:08
typo: response ?
|
| + 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 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:" |
|
Lei Zhang
2014/11/06 04:08:08
variable is not used for anything?
|
| + + 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; |
| +} |
| + |
| +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) { |
|
Lei Zhang
2014/11/06 04:08:08
URL should be lower case.
|
| + 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_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* pThis, |
| + int fileFlag, |
| + FPDF_WIDESTRING wsURL, |
| + const char* mode) { |
| + std::string url_str = "NULL"; |
|
Lei Zhang
2014/11/06 04:08:08
This variable is being set but not used for anythi
|
| + if (wsURL != NULL) { |
| + 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 // _PDF_USE_XFA_ |
| + |
| int PDFiumEngine::GetBlock(void* param, unsigned long position, |
| unsigned char* buffer, unsigned long size) { |
| DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| @@ -920,9 +1224,11 @@ void PDFiumEngine::FinishLoadingDocument() { |
| void PDFiumEngine::UnsupportedFeature(int type) { |
| std::string feature; |
| switch (type) { |
| +#ifndef _PDF_USE_XFA_ |
| case FPDF_UNSP_DOC_XFAFORM: |
| feature = "XFA"; |
| break; |
| +#endif |
| case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| feature = "Portfolios_Packages"; |
| break; |
| @@ -1348,8 +1654,13 @@ 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... |
| - client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| - control == FPDF_FORMFIELD_COMBOBOX); |
| +#ifdef _PDF_USE_XFA_ |
| + client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD || |
| + 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 +2545,10 @@ void PDFiumEngine::ContinueLoadingDocument( |
| form_ = FPDFDOC_InitFormFillEnviroument( |
| doc_, static_cast<FPDF_FORMFILLINFO*>(this)); |
| +#ifdef _PDF_USE_XFA_ |
| + FPDF_LoadXFA(doc_); |
| +#endif |
| + |
| FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); |
| FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); |
| } |