Chromium Code Reviews| Index: fpdfsdk/fsdk_actionhandler.cpp |
| diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp |
| index 27f0d34066806b9f06b937a16dde43087ca69290..e11fb747a63f157cea5931d84306681ccc26c1fe 100644 |
| --- a/fpdfsdk/fsdk_actionhandler.cpp |
| +++ b/fpdfsdk/fsdk_actionhandler.cpp |
| @@ -17,8 +17,41 @@ |
| #include "fpdfsdk/javascript/ijs_runtime.h" |
| #include "third_party/base/stl_util.h" |
| -CPDFSDK_ActionHandler::CPDFSDK_ActionHandler() |
| - : m_pFormActionHandler(new CPDFSDK_FormActionHandler) {} |
| +class NoJsActionHandler { |
| + public: |
| + NoJsActionHandler(const CPDF_Action&, CPDFSDK_Document*); |
| + void Run(); |
| + |
| + private: |
| + static void DoAction_GoTo(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_GoToR(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_Launch(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_URI(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_Named(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_SetOCGState(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_Hide(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_SubmitForm(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_ResetForm(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + static void DoAction_ImportData(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action); |
| + |
| + CPDF_Action m_action; |
| + CPDFSDK_Document* m_document; |
| + |
| + typedef void (*Callback)(CPDFSDK_Document*, const CPDF_Action&); |
| + Callback m_callback = nullptr; |
|
Tom Sepez
2016/08/09 21:11:20
Instead of storing the callback, can we store the
|
| +}; |
| + |
| +CPDFSDK_ActionHandler::CPDFSDK_ActionHandler() {} |
| CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler() {} |
| @@ -129,7 +162,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| @@ -173,7 +206,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| @@ -185,6 +218,11 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction( |
| return TRUE; |
| } |
| +FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) { |
| + ASSERT(pDocument); |
| + return TRUE; |
| +} |
| + |
| FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction( |
| const CPDF_Action& action, |
| CPDF_AAction::AActionType type, |
| @@ -206,7 +244,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| if (!IsValidDocView(pDocument)) |
| @@ -255,7 +293,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| @@ -300,7 +338,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| @@ -345,7 +383,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark( |
| } |
| } |
| } else { |
| - DoAction_NoJs(action, pDocument); |
| + NoJsActionHandler(action, pDocument).Run(); |
| } |
| for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| @@ -357,64 +395,49 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark( |
| return TRUE; |
| } |
| -void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, |
| - CPDFSDK_Document* pDocument) { |
| - ASSERT(pDocument); |
| - |
| - switch (action.GetType()) { |
| +NoJsActionHandler::NoJsActionHandler(const CPDF_Action& action, |
| + CPDFSDK_Document* document) |
| + : m_action(action), m_document(document) { |
| + switch (m_action.GetType()) { |
| case CPDF_Action::GoTo: |
| - DoAction_GoTo(pDocument, action); |
| + m_callback = &DoAction_GoTo; |
| break; |
| case CPDF_Action::GoToR: |
| - DoAction_GoToR(pDocument, action); |
| - break; |
| - case CPDF_Action::GoToE: |
| + m_callback = &DoAction_GoToR; |
| break; |
| case CPDF_Action::Launch: |
| - DoAction_Launch(pDocument, action); |
| - break; |
| - case CPDF_Action::Thread: |
| + m_callback = &DoAction_Launch; |
| break; |
| case CPDF_Action::URI: |
| - DoAction_URI(pDocument, action); |
| - break; |
| - case CPDF_Action::Sound: |
| - break; |
| - case CPDF_Action::Movie: |
| + m_callback = &DoAction_URI; |
| break; |
| case CPDF_Action::Hide: |
| - if (m_pFormActionHandler) { |
| - m_pFormActionHandler->DoAction_Hide(action, pDocument); |
| - } |
| + m_callback = &DoAction_Hide; |
| break; |
| case CPDF_Action::Named: |
| - DoAction_Named(pDocument, action); |
| + m_callback = &DoAction_Named; |
| break; |
| case CPDF_Action::SubmitForm: |
| - if (m_pFormActionHandler) { |
| - m_pFormActionHandler->DoAction_SubmitForm(action, pDocument); |
| - } |
| + m_callback = &DoAction_SubmitForm; |
| break; |
| case CPDF_Action::ResetForm: |
| - if (m_pFormActionHandler) { |
| - m_pFormActionHandler->DoAction_ResetForm(action, pDocument); |
| - } |
| + m_callback = &DoAction_ResetForm; |
| break; |
| case CPDF_Action::ImportData: |
| - if (m_pFormActionHandler) { |
| - m_pFormActionHandler->DoAction_ImportData(action, pDocument); |
| - } |
| + m_callback = &DoAction_ImportData; |
| break; |
| case CPDF_Action::JavaScript: |
| ASSERT(FALSE); |
| break; |
| case CPDF_Action::SetOCGState: |
| - DoAction_SetOCGState(pDocument, action); |
| + m_callback = &DoAction_SetOCGState; |
| break; |
| + case CPDF_Action::GoToE: |
| + case CPDF_Action::Thread: |
| + case CPDF_Action::Sound: |
| + case CPDF_Action::Movie: |
| case CPDF_Action::Rendition: |
| - break; |
| case CPDF_Action::Trans: |
| - break; |
| case CPDF_Action::GoTo3DView: |
| break; |
| default: |
| @@ -422,13 +445,16 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, |
| } |
| } |
| -FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) { |
| - ASSERT(pDocument); |
| - return TRUE; |
| +void NoJsActionHandler::Run() { |
| + if (!m_callback) |
| + return; |
| + |
| + ASSERT(m_document); |
| + m_callback(m_document, m_action); |
| } |
| -void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) { |
| +void NoJsActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| ASSERT(action.GetDict()); |
| CPDF_Document* pPDFDocument = pDocument->GetPDFDocument(); |
| @@ -454,14 +480,14 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, |
| delete[] pPosAry; |
| } |
| -void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) {} |
| +void NoJsActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) {} |
| -void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) {} |
| +void NoJsActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) {} |
| -void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) { |
| +void NoJsActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| ASSERT(action.GetDict()); |
| CPDFDoc_Environment* pApp = pDocument->GetEnv(); |
| @@ -469,16 +495,16 @@ void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, |
| pApp->FFI_DoURIAction(sURI.c_str()); |
| } |
| -void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) { |
| +void NoJsActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| ASSERT(action.GetDict()); |
| CFX_ByteString csName = action.GetNamedAction(); |
| pDocument->GetEnv()->FFI_ExecuteNamedAction(csName.c_str()); |
| } |
| -void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, |
| - const CPDF_Action& action) {} |
| +void NoJsActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) {} |
| void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, |
| CPDF_FormField* pFormField, |
| @@ -606,39 +632,28 @@ void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( |
| pRuntime->ReleaseContext(pContext); |
| } |
| -FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, |
| - CPDFSDK_Document* pDocument) { |
| +void NoJsActionHandler::DoAction_Hide(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
| - if (pInterForm->DoAction_Hide(action)) { |
| + if (pInterForm->DoAction_Hide(action)) |
| pDocument->SetChangeMark(); |
| - return TRUE; |
| - } |
| - |
| - return FALSE; |
| } |
| -FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm( |
| - const CPDF_Action& action, |
| - CPDFSDK_Document* pDocument) { |
| +void NoJsActionHandler::DoAction_SubmitForm(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
| - return pInterForm->DoAction_SubmitForm(action); |
| + pInterForm->DoAction_SubmitForm(action); |
| } |
| -FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm( |
| - const CPDF_Action& action, |
| - CPDFSDK_Document* pDocument) { |
| +void NoJsActionHandler::DoAction_ResetForm(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
| - return pInterForm->DoAction_ResetForm(action); |
| + pInterForm->DoAction_ResetForm(action); |
| } |
| -FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData( |
| - const CPDF_Action& action, |
| - CPDFSDK_Document* pDocument) { |
| +void NoJsActionHandler::DoAction_ImportData(CPDFSDK_Document* pDocument, |
| + const CPDF_Action& action) { |
| CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
| - if (pInterForm->DoAction_ImportData(action)) { |
| + if (pInterForm->DoAction_ImportData(action)) |
| pDocument->SetChangeMark(); |
| - return TRUE; |
| - } |
| - |
| - return FALSE; |
| } |