diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-07-16 20:49:56 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-16 20:49:56 +0000 |
commit | c30b4e16885c8fd5f59965f48b61ec033ae4691a (patch) | |
tree | d15118e1f461ef5654f94c6d63e8acb96275800f | |
parent | 4cf61e07625888a3b56c4de97719c87cf514fb7f (diff) | |
download | pdfium-c30b4e16885c8fd5f59965f48b61ec033ae4691a.tar.xz |
Alert embedder when attempting to save XFA form
This CL adds an experimental callback to the form fill API that
allows PDFium to signal to the embedder that an attempt call save
occurred. The embedder is responsible for showing an appropriate
UI when this occurs. When PDF saving is implemented the API can
be removed.
BUG=pdfium:953
Change-Id: Iba30f4d0547fe773b793e499995be426626092a0
Reviewed-on: https://pdfium-review.googlesource.com/35870
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | fpdfsdk/cpdfsdk_formfillenvironment.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_formfillenvironment.h | 4 | ||||
-rw-r--r-- | fpdfsdk/fpdf_formfill.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 1 | ||||
-rw-r--r-- | fxjs/cjs_app.cpp | 6 | ||||
-rw-r--r-- | public/fpdf_formfill.h | 20 |
6 files changed, 50 insertions, 1 deletions
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index b224fc75d0..649d3bbd2e 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -39,7 +39,8 @@ CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( m_pCPDFDoc(pDoc), m_pSysHandler(pdfium::MakeUnique<CFX_SystemHandler>(this)), m_bChangeMask(false), - m_bBeingDestroyed(false) {} + m_bBeingDestroyed(false), + m_SaveCalled(nullptr) {} CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { m_bBeingDestroyed = true; @@ -629,6 +630,13 @@ CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { return m_pInterForm.get(); } +void CPDFSDK_FormFillEnvironment::SaveCalled() { + if (!m_pInfo || !m_SaveCalled) + return; + + m_SaveCalled(m_pInfo); +} + void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) { for (const auto& it : m_PageMap) { diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index dacc02f95d..1cf078e3aa 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -208,6 +208,9 @@ class CPDFSDK_FormFillEnvironment CPDFSDK_ActionHandler* GetActionHandler(); // Creates if not present. CPDFSDK_InterForm* GetInterForm(); // Creates if not present. + void SetSaveCalled(FORM_SAVECALLED callback) { m_SaveCalled = callback; } + void SaveCalled(); + private: IPDF_Page* GetPage(int nIndex); @@ -223,6 +226,7 @@ class CPDFSDK_FormFillEnvironment std::unique_ptr<CFX_SystemHandler> m_pSysHandler; bool m_bChangeMask; bool m_bBeingDestroyed; + FORM_SAVECALLED m_SaveCalled; }; #endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_ diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp index 792ced773f..1af34b552f 100644 --- a/fpdfsdk/fpdf_formfill.cpp +++ b/fpdfsdk/fpdf_formfill.cpp @@ -360,6 +360,16 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { delete pFormFillEnv; } +FPDF_EXPORT void FPDF_CALLCONV FORM_SetSaveCallback(FORM_SAVECALLED callback, + FPDF_FORMHANDLE hHandle) { + CPDFSDK_FormFillEnvironment* pFormFillEnv = + HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) + return; + + pFormFillEnv->SetSaveCalled(callback); +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index 114a6b0024..4faf5bbf0f 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -247,6 +247,7 @@ int CheckPDFiumCApi() { #endif CHK(FORM_Redo); CHK(FORM_ReplaceSelection); + CHK(FORM_SetSaveCallback); CHK(FORM_Undo); CHK(FPDFDOC_ExitFormFillEnvironment); CHK(FPDFDOC_InitFormFillEnvironment); diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index ad155b787c..fd98670c51 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -404,6 +404,12 @@ void CJS_App::ClearTimerCommon(CJS_Runtime* pRuntime, CJS_Return CJS_App::execMenuItem( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { + if (params.size() > 0 && IsTypeKnown(params[0])) { + WideString item = pRuntime->ToWideString(params[0]); + if (item == L"SaveAs" && pRuntime->GetFormFillEnv()) + pRuntime->GetFormFillEnv()->SaveCalled(); + } + return CJS_Return(JSMessage::kNotSupportedError); } diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h index 0bc08ec54b..68ffcda56d 100644 --- a/public/fpdf_formfill.h +++ b/public/fpdf_formfill.h @@ -1113,6 +1113,26 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_EXPORT void FPDF_CALLCONV FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle); +typedef void (*FORM_SAVECALLED)(FPDF_FORMFILLINFO*); +/** + * Experimental API + * Function: FORM_SetSaveCallback + * This method is used to set a callback handler for when Save is + * attempted by a PDF. Should be invoked after user successfully + * loaded a PDF page, and method FPDFDOC_InitFormFillEnvironment had + * been invoked. + * Parameters: + * callback - Function pointer to the callback to be called when a + * Save is attempted. If NULL then no function will be + * invoked.. + * hHandle - Handle to the form fill module. Returned by + * FPDFDOC_InitFormFillEnvironment. + * Return Value: + * NONE. + **/ +FPDF_EXPORT void FPDF_CALLCONV FORM_SetSaveCallback(FORM_SAVECALLED callback, + FPDF_FORMHANDLE hHandle); + /** * Function: FORM_OnAfterLoadPage * This method is required for implementing all the form related |