blob: ea7d2c3a08eaa1b492e6484cf6129a985371b592 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Tom Sepez7b5bc262015-03-05 16:44:22 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/fsdk_actionhandler.h"
Dan Sinclair3ebd1212016-03-09 09:59:23 -05008
9#include <set>
Tom Sepezd7188f72017-05-02 15:10:58 -070010#include <vector>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011
dsinclair488b7ad2016-10-04 11:55:50 -070012#include "core/fpdfapi/parser/cpdf_array.h"
dsinclair1727aee2016-09-29 13:12:56 -070013#include "core/fpdfdoc/cpdf_formfield.h"
14#include "core/fpdfdoc/cpdf_interform.h"
dsinclair735606d2016-10-05 15:47:02 -070015#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070016#include "fpdfsdk/cpdfsdk_interform.h"
17#include "fpdfsdk/fsdk_define.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080018#include "fpdfsdk/javascript/ijs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070019#include "fpdfsdk/javascript/ijs_runtime.h"
Lei Zhangb45324b2017-05-22 17:05:40 -070020#include "third_party/base/logging.h"
Tom Sepez6c7508b2016-01-20 14:59:25 -080021#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
tsepez4cf55152016-11-02 14:37:54 -070023bool CPDFSDK_ActionHandler::DoAction_DocOpen(
dsinclair19c198b2016-10-11 12:51:37 -070024 const CPDF_Action& action,
25 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Tom Sepez6c7508b2016-01-20 14:59:25 -080026 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -070027 return ExecuteDocumentOpenAction(action, pFormFillEnv, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028}
29
tsepez4cf55152016-11-02 14:37:54 -070030bool CPDFSDK_ActionHandler::DoAction_JavaScript(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 const CPDF_Action& JsAction,
Ryan Harrison275e2602017-09-18 14:23:18 -040032 WideString csJSName,
dsinclair19c198b2016-10-11 12:51:37 -070033 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 if (JsAction.GetType() == CPDF_Action::JavaScript) {
Ryan Harrison275e2602017-09-18 14:23:18 -040035 WideString swJS = JsAction.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -070037 RunDocumentOpenJavaScript(pFormFillEnv, csJSName, swJS);
tsepez4cf55152016-11-02 14:37:54 -070038 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 }
40 }
41
tsepez4cf55152016-11-02 14:37:54 -070042 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
tsepez4cf55152016-11-02 14:37:54 -070045bool CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 const CPDF_Action& JsAction,
47 CPDF_AAction::AActionType type,
dsinclair19c198b2016-10-11 12:51:37 -070048 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 CPDF_FormField* pFormField,
50 PDFSDK_FieldAction& data) {
dsinclair19c198b2016-10-11 12:51:37 -070051 ASSERT(pFormFillEnv);
52 if (pFormFillEnv->IsJSInitiated() &&
53 JsAction.GetType() == CPDF_Action::JavaScript) {
Ryan Harrison275e2602017-09-18 14:23:18 -040054 WideString swJS = JsAction.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -070056 RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS);
tsepez4cf55152016-11-02 14:37:54 -070057 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 }
59 }
tsepez4cf55152016-11-02 14:37:54 -070060 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061}
62
tsepez4cf55152016-11-02 14:37:54 -070063bool CPDFSDK_ActionHandler::DoAction_Page(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 const CPDF_Action& action,
65 enum CPDF_AAction::AActionType eType,
dsinclair19c198b2016-10-11 12:51:37 -070066 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Tom Sepez6c7508b2016-01-20 14:59:25 -080067 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -070068 return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
tsepez4cf55152016-11-02 14:37:54 -070071bool CPDFSDK_ActionHandler::DoAction_Document(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 const CPDF_Action& action,
73 enum CPDF_AAction::AActionType eType,
dsinclair19c198b2016-10-11 12:51:37 -070074 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Tom Sepez6c7508b2016-01-20 14:59:25 -080075 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -070076 return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
tsepez4cf55152016-11-02 14:37:54 -070079bool CPDFSDK_ActionHandler::DoAction_BookMark(
dsinclair19c198b2016-10-11 12:51:37 -070080 CPDF_Bookmark* pBookMark,
81 const CPDF_Action& action,
82 CPDF_AAction::AActionType type,
83 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Tom Sepez6c7508b2016-01-20 14:59:25 -080084 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -070085 return ExecuteBookMark(action, pFormFillEnv, pBookMark, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086}
87
tsepez4cf55152016-11-02 14:37:54 -070088bool CPDFSDK_ActionHandler::DoAction_Screen(
dsinclair19c198b2016-10-11 12:51:37 -070089 const CPDF_Action& action,
90 CPDF_AAction::AActionType type,
91 CPDFSDK_FormFillEnvironment* pFormFillEnv,
92 CPDFSDK_Annot* pScreen) {
Tom Sepez6c7508b2016-01-20 14:59:25 -080093 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -070094 return ExecuteScreenAction(action, type, pFormFillEnv, pScreen, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
tsepez4cf55152016-11-02 14:37:54 -070097bool CPDFSDK_ActionHandler::DoAction_Link(
dsinclair19c198b2016-10-11 12:51:37 -070098 const CPDF_Action& action,
99 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
Tom Sepez6c7508b2016-01-20 14:59:25 -0800100 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -0700101 return ExecuteLinkAction(action, pFormFillEnv, &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102}
103
tsepez4cf55152016-11-02 14:37:54 -0700104bool CPDFSDK_ActionHandler::DoAction_Field(
dsinclair19c198b2016-10-11 12:51:37 -0700105 const CPDF_Action& action,
106 CPDF_AAction::AActionType type,
107 CPDFSDK_FormFillEnvironment* pFormFillEnv,
108 CPDF_FormField* pFormField,
109 PDFSDK_FieldAction& data) {
Tom Sepez6c7508b2016-01-20 14:59:25 -0800110 std::set<CPDF_Dictionary*> visited;
dsinclair19c198b2016-10-11 12:51:37 -0700111 return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800112 &visited);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113}
114
tsepez4cf55152016-11-02 14:37:54 -0700115bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 const CPDF_Action& action,
dsinclair19c198b2016-10-11 12:51:37 -0700117 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800118 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800120 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700121 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122
Tom Sepez6c7508b2016-01-20 14:59:25 -0800123 visited->insert(pDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124
dsinclair19c198b2016-10-11 12:51:37 -0700125 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair19c198b2016-10-11 12:51:37 -0700127 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400128 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -0700130 RunDocumentOpenJavaScript(pFormFillEnv, L"", swJS);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 }
132 }
133 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700134 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 }
136
137 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
138 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700139 if (!ExecuteDocumentOpenAction(subaction, pFormFillEnv, visited))
tsepez4cf55152016-11-02 14:37:54 -0700140 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 }
142
tsepez4cf55152016-11-02 14:37:54 -0700143 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144}
145
tsepez4cf55152016-11-02 14:37:54 -0700146bool CPDFSDK_ActionHandler::ExecuteLinkAction(
Tom Sepez6c7508b2016-01-20 14:59:25 -0800147 const CPDF_Action& action,
dsinclair19c198b2016-10-11 12:51:37 -0700148 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800149 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800151 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700152 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Tom Sepez6c7508b2016-01-20 14:59:25 -0800154 visited->insert(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155
dsinclair4526faf2016-10-11 10:54:49 -0700156 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair4526faf2016-10-11 10:54:49 -0700158 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400159 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 if (!swJS.IsEmpty()) {
dsinclair4526faf2016-10-11 10:54:49 -0700161 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800162 IJS_EventContext* pContext = pRuntime->NewEventContext();
dsinclair4526faf2016-10-11 10:54:49 -0700163 pContext->OnLink_MouseUp(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164
Ryan Harrison275e2602017-09-18 14:23:18 -0400165 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700166 bool bRet = pContext->RunScript(swJS, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800167 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 if (!bRet) {
169 // FIXME: return error.
170 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 }
172 }
173 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700174 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 }
176
177 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
178 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700179 if (!ExecuteLinkAction(subaction, pFormFillEnv, visited))
tsepez4cf55152016-11-02 14:37:54 -0700180 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 }
182
tsepez4cf55152016-11-02 14:37:54 -0700183 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184}
185
tsepez4cf55152016-11-02 14:37:54 -0700186bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 const CPDF_Action& action,
188 CPDF_AAction::AActionType type,
dsinclair19c198b2016-10-11 12:51:37 -0700189 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800190 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800192 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700193 return false;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800194
Tom Sepez6c7508b2016-01-20 14:59:25 -0800195 visited->insert(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196
dsinclair19c198b2016-10-11 12:51:37 -0700197 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair19c198b2016-10-11 12:51:37 -0700199 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400200 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -0700202 RunDocumentPageJavaScript(pFormFillEnv, type, swJS);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 }
204 }
205 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700206 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
dsinclair19c198b2016-10-11 12:51:37 -0700209 if (!IsValidDocView(pFormFillEnv))
tsepez4cf55152016-11-02 14:37:54 -0700210 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
213 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700214 if (!ExecuteDocumentPageAction(subaction, type, pFormFillEnv, visited))
tsepez4cf55152016-11-02 14:37:54 -0700215 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217
tsepez4cf55152016-11-02 14:37:54 -0700218 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219}
220
tsepez4cf55152016-11-02 14:37:54 -0700221bool CPDFSDK_ActionHandler::IsValidField(
dsinclair19c198b2016-10-11 12:51:37 -0700222 CPDFSDK_FormFillEnvironment* pFormFillEnv,
223 CPDF_Dictionary* pFieldDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800224 ASSERT(pFieldDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225
dsinclair7cbe68e2016-10-12 11:56:23 -0700226 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Chris Palmer9047b8b2014-08-06 14:17:45 -0700227 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -0700228 return !!pPDFInterForm->GetFieldByDict(pFieldDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
tsepez4cf55152016-11-02 14:37:54 -0700231bool CPDFSDK_ActionHandler::ExecuteFieldAction(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 const CPDF_Action& action,
233 CPDF_AAction::AActionType type,
dsinclair19c198b2016-10-11 12:51:37 -0700234 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 CPDF_FormField* pFormField,
236 PDFSDK_FieldAction& data,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800237 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800239 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700240 return false;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800241
Tom Sepez6c7508b2016-01-20 14:59:25 -0800242 visited->insert(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
dsinclair19c198b2016-10-11 12:51:37 -0700244 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair19c198b2016-10-11 12:51:37 -0700246 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400247 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -0700249 RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS);
250 if (!IsValidField(pFormFillEnv, pFormField->GetFieldDict()))
tsepez4cf55152016-11-02 14:37:54 -0700251 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 }
253 }
254 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700255 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
259 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700260 if (!ExecuteFieldAction(subaction, type, pFormFillEnv, pFormField, data,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800261 visited))
tsepez4cf55152016-11-02 14:37:54 -0700262 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264
tsepez4cf55152016-11-02 14:37:54 -0700265 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700266}
267
tsepez4cf55152016-11-02 14:37:54 -0700268bool CPDFSDK_ActionHandler::ExecuteScreenAction(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 const CPDF_Action& action,
270 CPDF_AAction::AActionType type,
dsinclair19c198b2016-10-11 12:51:37 -0700271 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 CPDFSDK_Annot* pScreen,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800273 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800275 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700276 return false;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800277
Tom Sepez6c7508b2016-01-20 14:59:25 -0800278 visited->insert(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
dsinclair19c198b2016-10-11 12:51:37 -0700280 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair19c198b2016-10-11 12:51:37 -0700282 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400283 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -0700285 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800286 IJS_EventContext* pContext = pRuntime->NewEventContext();
Ryan Harrison275e2602017-09-18 14:23:18 -0400287 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700288 bool bRet = pContext->RunScript(swJS, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800289 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 if (!bRet) {
Tom Sepez33420902015-10-13 15:00:10 -0700291 // FIXME: return error.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 }
294 }
295 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700296 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
300 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700301 if (!ExecuteScreenAction(subaction, type, pFormFillEnv, pScreen, visited))
tsepez4cf55152016-11-02 14:37:54 -0700302 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304
tsepez4cf55152016-11-02 14:37:54 -0700305 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306}
307
tsepez4cf55152016-11-02 14:37:54 -0700308bool CPDFSDK_ActionHandler::ExecuteBookMark(
Tom Sepez6c7508b2016-01-20 14:59:25 -0800309 const CPDF_Action& action,
dsinclair19c198b2016-10-11 12:51:37 -0700310 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Tom Sepez6c7508b2016-01-20 14:59:25 -0800311 CPDF_Bookmark* pBookmark,
312 std::set<CPDF_Dictionary*>* visited) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 CPDF_Dictionary* pDict = action.GetDict();
Tom Sepez6c7508b2016-01-20 14:59:25 -0800314 if (pdfium::ContainsKey(*visited, pDict))
tsepez4cf55152016-11-02 14:37:54 -0700315 return false;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800316
Tom Sepez6c7508b2016-01-20 14:59:25 -0800317 visited->insert(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700318
dsinclair19c198b2016-10-11 12:51:37 -0700319 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 if (action.GetType() == CPDF_Action::JavaScript) {
dsinclair19c198b2016-10-11 12:51:37 -0700321 if (pFormFillEnv->IsJSInitiated()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400322 WideString swJS = action.GetJavaScript();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 if (!swJS.IsEmpty()) {
dsinclair19c198b2016-10-11 12:51:37 -0700324 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800325 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 pContext->OnBookmark_MouseUp(pBookmark);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327
Ryan Harrison275e2602017-09-18 14:23:18 -0400328 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700329 bool bRet = pContext->RunScript(swJS, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800330 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 if (!bRet) {
Tom Sepez33420902015-10-13 15:00:10 -0700332 // FIXME: return error.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 }
335 }
336 } else {
dsinclair19c198b2016-10-11 12:51:37 -0700337 DoAction_NoJs(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700339
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
341 CPDF_Action subaction = action.GetSubAction(i);
dsinclair19c198b2016-10-11 12:51:37 -0700342 if (!ExecuteBookMark(subaction, pFormFillEnv, pBookmark, visited))
tsepez4cf55152016-11-02 14:37:54 -0700343 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700345
tsepez4cf55152016-11-02 14:37:54 -0700346 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347}
348
dsinclair19c198b2016-10-11 12:51:37 -0700349void CPDFSDK_ActionHandler::DoAction_NoJs(
350 const CPDF_Action& action,
351 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
352 ASSERT(pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 switch (action.GetType()) {
355 case CPDF_Action::GoTo:
dsinclair19c198b2016-10-11 12:51:37 -0700356 DoAction_GoTo(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 break;
358 case CPDF_Action::GoToR:
dsinclair19c198b2016-10-11 12:51:37 -0700359 DoAction_GoToR(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 break;
361 case CPDF_Action::GoToE:
362 break;
363 case CPDF_Action::Launch:
dsinclair19c198b2016-10-11 12:51:37 -0700364 DoAction_Launch(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 break;
366 case CPDF_Action::Thread:
367 break;
368 case CPDF_Action::URI:
dsinclair19c198b2016-10-11 12:51:37 -0700369 DoAction_URI(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 break;
371 case CPDF_Action::Sound:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 break;
373 case CPDF_Action::Movie:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 break;
375 case CPDF_Action::Hide:
dsinclair19c198b2016-10-11 12:51:37 -0700376 DoAction_Hide(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 break;
378 case CPDF_Action::Named:
dsinclair19c198b2016-10-11 12:51:37 -0700379 DoAction_Named(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 break;
381 case CPDF_Action::SubmitForm:
dsinclair19c198b2016-10-11 12:51:37 -0700382 DoAction_SubmitForm(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 break;
384 case CPDF_Action::ResetForm:
dsinclair19c198b2016-10-11 12:51:37 -0700385 DoAction_ResetForm(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 break;
387 case CPDF_Action::ImportData:
dsinclair19c198b2016-10-11 12:51:37 -0700388 DoAction_ImportData(action, pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 break;
390 case CPDF_Action::JavaScript:
Lei Zhangb45324b2017-05-22 17:05:40 -0700391 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 break;
393 case CPDF_Action::SetOCGState:
dsinclair19c198b2016-10-11 12:51:37 -0700394 DoAction_SetOCGState(pFormFillEnv, action);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 break;
396 case CPDF_Action::Rendition:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 break;
398 case CPDF_Action::Trans:
399 break;
400 case CPDF_Action::GoTo3DView:
401 break;
402 default:
403 break;
404 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405}
406
tsepez4cf55152016-11-02 14:37:54 -0700407bool CPDFSDK_ActionHandler::IsValidDocView(
dsinclair19c198b2016-10-11 12:51:37 -0700408 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
409 ASSERT(pFormFillEnv);
tsepez4cf55152016-11-02 14:37:54 -0700410 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700411}
412
dsinclair19c198b2016-10-11 12:51:37 -0700413void CPDFSDK_ActionHandler::DoAction_GoTo(
414 CPDFSDK_FormFillEnvironment* pFormFillEnv,
415 const CPDF_Action& action) {
Wei Li0fc6b252016-03-01 16:29:41 -0800416 ASSERT(action.GetDict());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417
dsinclair7cbe68e2016-10-12 11:56:23 -0700418 CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument();
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400419 ASSERT(pPDFDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 CPDF_Dest MyDest = action.GetDest(pPDFDocument);
422 int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
423 int nFitType = MyDest.GetZoomMode();
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400424 const CPDF_Array* pMyArray = ToArray(MyDest.GetObject());
Tom Sepezd7188f72017-05-02 15:10:58 -0700425 std::vector<float> posArray;
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400426 if (pMyArray) {
Tom Sepezd7188f72017-05-02 15:10:58 -0700427 for (size_t i = 2; i < pMyArray->GetCount(); i++)
428 posArray.push_back(pMyArray->GetFloatAt(i));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 }
Tom Sepezd7188f72017-05-02 15:10:58 -0700430 pFormFillEnv->DoGoToAction(nPageIndex, nFitType, posArray.data(),
431 posArray.size());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
dsinclair19c198b2016-10-11 12:51:37 -0700434void CPDFSDK_ActionHandler::DoAction_GoToR(
435 CPDFSDK_FormFillEnvironment* pFormFillEnv,
436 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437
dsinclair19c198b2016-10-11 12:51:37 -0700438void CPDFSDK_ActionHandler::DoAction_Launch(
439 CPDFSDK_FormFillEnvironment* pFormFillEnv,
440 const CPDF_Action& action) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441
dsinclair19c198b2016-10-11 12:51:37 -0700442void CPDFSDK_ActionHandler::DoAction_URI(
443 CPDFSDK_FormFillEnvironment* pFormFillEnv,
444 const CPDF_Action& action) {
Wei Li0fc6b252016-03-01 16:29:41 -0800445 ASSERT(action.GetDict());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446
Ryan Harrison275e2602017-09-18 14:23:18 -0400447 ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument());
dsinclair19c198b2016-10-11 12:51:37 -0700448 pFormFillEnv->DoURIAction(sURI.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449}
450
dsinclair19c198b2016-10-11 12:51:37 -0700451void CPDFSDK_ActionHandler::DoAction_Named(
452 CPDFSDK_FormFillEnvironment* pFormFillEnv,
453 const CPDF_Action& action) {
Wei Li0fc6b252016-03-01 16:29:41 -0800454 ASSERT(action.GetDict());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700455
Ryan Harrison275e2602017-09-18 14:23:18 -0400456 ByteString csName = action.GetNamedAction();
dsinclair19c198b2016-10-11 12:51:37 -0700457 pFormFillEnv->ExecuteNamedAction(csName.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458}
459
dsinclair19c198b2016-10-11 12:51:37 -0700460void CPDFSDK_ActionHandler::DoAction_SetOCGState(
461 CPDFSDK_FormFillEnvironment* pFormFillEnv,
462 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463
dsinclair19c198b2016-10-11 12:51:37 -0700464void CPDFSDK_ActionHandler::RunFieldJavaScript(
465 CPDFSDK_FormFillEnvironment* pFormFillEnv,
466 CPDF_FormField* pFormField,
467 CPDF_AAction::AActionType type,
468 PDFSDK_FieldAction& data,
Ryan Harrison275e2602017-09-18 14:23:18 -0400469 const WideString& script) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 ASSERT(type != CPDF_AAction::Calculate);
471 ASSERT(type != CPDF_AAction::Format);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700472
dsinclair19c198b2016-10-11 12:51:37 -0700473 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800474 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 switch (type) {
476 case CPDF_AAction::CursorEnter:
477 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
478 break;
479 case CPDF_AAction::CursorExit:
480 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
481 break;
482 case CPDF_AAction::ButtonDown:
483 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
484 break;
485 case CPDF_AAction::ButtonUp:
486 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
487 break;
488 case CPDF_AAction::GetFocus:
489 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
490 data.sValue);
491 break;
492 case CPDF_AAction::LoseFocus:
493 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
494 data.sValue);
495 break;
496 case CPDF_AAction::KeyStroke:
497 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
498 data.bModifier, data.nSelEnd, data.nSelStart,
499 data.bShift, pFormField, data.sValue,
500 data.bWillCommit, data.bFieldFull, data.bRC);
501 break;
502 case CPDF_AAction::Validate:
503 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
504 data.bModifier, data.bShift, pFormField,
505 data.sValue, data.bRC);
506 break;
507 default:
Lei Zhangb45324b2017-05-22 17:05:40 -0700508 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 break;
510 }
511
Ryan Harrison275e2602017-09-18 14:23:18 -0400512 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700513 bool bRet = pContext->RunScript(script, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800514 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 if (!bRet) {
Tom Sepez33420902015-10-13 15:00:10 -0700516 // FIXME: return error.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518}
519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
dsinclair19c198b2016-10-11 12:51:37 -0700521 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400522 const WideString& sScriptName,
523 const WideString& script) {
dsinclair19c198b2016-10-11 12:51:37 -0700524 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800525 IJS_EventContext* pContext = pRuntime->NewEventContext();
dsinclair19c198b2016-10-11 12:51:37 -0700526 pContext->OnDoc_Open(pFormFillEnv, sScriptName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527
Ryan Harrison275e2602017-09-18 14:23:18 -0400528 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700529 bool bRet = pContext->RunScript(script, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800530 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 if (!bRet) {
Tom Sepez33420902015-10-13 15:00:10 -0700532 // FIXME: return error.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700534}
535
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
dsinclair19c198b2016-10-11 12:51:37 -0700537 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 CPDF_AAction::AActionType type,
Ryan Harrison275e2602017-09-18 14:23:18 -0400539 const WideString& script) {
dsinclair19c198b2016-10-11 12:51:37 -0700540 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800541 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 switch (type) {
543 case CPDF_AAction::OpenPage:
dsinclair19c198b2016-10-11 12:51:37 -0700544 pContext->OnPage_Open(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 break;
546 case CPDF_AAction::ClosePage:
dsinclair19c198b2016-10-11 12:51:37 -0700547 pContext->OnPage_Close(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 break;
549 case CPDF_AAction::CloseDocument:
dsinclair19c198b2016-10-11 12:51:37 -0700550 pContext->OnDoc_WillClose(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 break;
552 case CPDF_AAction::SaveDocument:
dsinclair19c198b2016-10-11 12:51:37 -0700553 pContext->OnDoc_WillSave(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 break;
555 case CPDF_AAction::DocumentSaved:
dsinclair19c198b2016-10-11 12:51:37 -0700556 pContext->OnDoc_DidSave(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 break;
558 case CPDF_AAction::PrintDocument:
dsinclair19c198b2016-10-11 12:51:37 -0700559 pContext->OnDoc_WillPrint(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 break;
561 case CPDF_AAction::DocumentPrinted:
dsinclair19c198b2016-10-11 12:51:37 -0700562 pContext->OnDoc_DidPrint(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 break;
564 case CPDF_AAction::PageVisible:
dsinclair19c198b2016-10-11 12:51:37 -0700565 pContext->OnPage_InView(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 break;
567 case CPDF_AAction::PageInvisible:
dsinclair19c198b2016-10-11 12:51:37 -0700568 pContext->OnPage_OutView(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 break;
570 default:
Lei Zhangb45324b2017-05-22 17:05:40 -0700571 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 break;
573 }
574
Ryan Harrison275e2602017-09-18 14:23:18 -0400575 WideString csInfo;
tsepez4cf55152016-11-02 14:37:54 -0700576 bool bRet = pContext->RunScript(script, &csInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800577 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 if (!bRet) {
Tom Sepez33420902015-10-13 15:00:10 -0700579 // FIXME: return error.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581}
582
tsepez4cf55152016-11-02 14:37:54 -0700583bool CPDFSDK_ActionHandler::DoAction_Hide(
dsinclair19c198b2016-10-11 12:51:37 -0700584 const CPDF_Action& action,
585 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700586 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 if (pInterForm->DoAction_Hide(action)) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700588 pFormFillEnv->SetChangeMark();
tsepez4cf55152016-11-02 14:37:54 -0700589 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591
tsepez4cf55152016-11-02 14:37:54 -0700592 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700593}
594
tsepez4cf55152016-11-02 14:37:54 -0700595bool CPDFSDK_ActionHandler::DoAction_SubmitForm(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596 const CPDF_Action& action,
dsinclair19c198b2016-10-11 12:51:37 -0700597 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700598 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 return pInterForm->DoAction_SubmitForm(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700600}
601
tsepez4cf55152016-11-02 14:37:54 -0700602bool CPDFSDK_ActionHandler::DoAction_ResetForm(
dsinclair19c198b2016-10-11 12:51:37 -0700603 const CPDF_Action& action,
604 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700605 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhang96660d62015-12-14 18:27:25 -0800606 return pInterForm->DoAction_ResetForm(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
tsepez4cf55152016-11-02 14:37:54 -0700609bool CPDFSDK_ActionHandler::DoAction_ImportData(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 const CPDF_Action& action,
dsinclair19c198b2016-10-11 12:51:37 -0700611 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700612 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 if (pInterForm->DoAction_ImportData(action)) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700614 pFormFillEnv->SetChangeMark();
tsepez4cf55152016-11-02 14:37:54 -0700615 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 }
Tom Sepez7b5bc262015-03-05 16:44:22 -0800617
tsepez4cf55152016-11-02 14:37:54 -0700618 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}