John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 7 | #include "fpdfsdk/include/fsdk_actionhandler.h" |
| 8 | #include "fpdfsdk/include/fsdk_define.h" |
| 9 | #include "fpdfsdk/include/fsdk_mgr.h" |
| 10 | #include "fpdfsdk/include/javascript/IJavaScript.h" |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 11 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | |
Tom Sepez | 3b5f124 | 2015-09-01 14:06:55 -0700 | [diff] [blame] | 13 | CPDFSDK_ActionHandler::CPDFSDK_ActionHandler() |
| 14 | : m_pFormActionHandler(new CPDFSDK_FormActionHandler) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | } |
| 16 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 17 | FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, |
| 18 | CPDFSDK_Document* pDocument) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 19 | std::set<CPDF_Dictionary*> visited; |
| 20 | return ExecuteDocumentOpenAction(action, pDocument, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript( |
| 24 | const CPDF_Action& JsAction, |
| 25 | CFX_WideString csJSName, |
| 26 | CPDFSDK_Document* pDocument) { |
| 27 | if (JsAction.GetType() == CPDF_Action::JavaScript) { |
| 28 | CFX_WideString swJS = JsAction.GetJavaScript(); |
| 29 | if (!swJS.IsEmpty()) { |
| 30 | RunDocumentOpenJavaScript(pDocument, csJSName, swJS); |
| 31 | return TRUE; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript( |
| 39 | const CPDF_Action& JsAction, |
| 40 | CPDF_AAction::AActionType type, |
| 41 | CPDFSDK_Document* pDocument, |
| 42 | CPDF_FormField* pFormField, |
| 43 | PDFSDK_FieldAction& data) { |
| 44 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 45 | ASSERT(pEnv); |
| 46 | if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript) { |
| 47 | CFX_WideString swJS = JsAction.GetJavaScript(); |
| 48 | if (!swJS.IsEmpty()) { |
| 49 | RunFieldJavaScript(pDocument, pFormField, type, data, swJS); |
| 50 | return TRUE; |
| 51 | } |
| 52 | } |
| 53 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Page( |
| 57 | const CPDF_Action& action, |
| 58 | enum CPDF_AAction::AActionType eType, |
| 59 | CPDFSDK_Document* pDocument) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 60 | std::set<CPDF_Dictionary*> visited; |
| 61 | return ExecuteDocumentPageAction(action, eType, pDocument, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Document( |
| 65 | const CPDF_Action& action, |
| 66 | enum CPDF_AAction::AActionType eType, |
| 67 | CPDFSDK_Document* pDocument) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 68 | std::set<CPDF_Dictionary*> visited; |
| 69 | return ExecuteDocumentPageAction(action, eType, pDocument, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark* pBookMark, |
| 73 | const CPDF_Action& action, |
| 74 | CPDF_AAction::AActionType type, |
| 75 | CPDFSDK_Document* pDocument) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 76 | std::set<CPDF_Dictionary*> visited; |
| 77 | return ExecuteBookMark(action, pDocument, pBookMark, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, |
| 81 | CPDF_AAction::AActionType type, |
| 82 | CPDFSDK_Document* pDocument, |
| 83 | CPDFSDK_Annot* pScreen) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 84 | std::set<CPDF_Dictionary*> visited; |
| 85 | return ExecuteScreenAction(action, type, pDocument, pScreen, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, |
| 89 | CPDFSDK_Document* pDocument) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 90 | std::set<CPDF_Dictionary*> visited; |
| 91 | return ExecuteLinkAction(action, pDocument, &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, |
| 95 | CPDF_AAction::AActionType type, |
| 96 | CPDFSDK_Document* pDocument, |
| 97 | CPDF_FormField* pFormField, |
| 98 | PDFSDK_FieldAction& data) { |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 99 | std::set<CPDF_Dictionary*> visited; |
| 100 | return ExecuteFieldAction(action, type, pDocument, pFormField, data, |
| 101 | &visited); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( |
| 105 | const CPDF_Action& action, |
| 106 | CPDFSDK_Document* pDocument, |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 107 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 109 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | return FALSE; |
| 111 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 112 | visited->insert(pDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | |
| 114 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 115 | ASSERT(pEnv); |
| 116 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 117 | if (pEnv->IsJSInitiated()) { |
| 118 | CFX_WideString swJS = action.GetJavaScript(); |
| 119 | if (!swJS.IsEmpty()) { |
| 120 | RunDocumentOpenJavaScript(pDocument, L"", swJS); |
| 121 | } |
| 122 | } |
| 123 | } else { |
| 124 | DoAction_NoJs(action, pDocument); |
| 125 | } |
| 126 | |
| 127 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 128 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 129 | if (!ExecuteDocumentOpenAction(subaction, pDocument, visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | return FALSE; |
| 131 | } |
| 132 | |
| 133 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 136 | FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction( |
| 137 | const CPDF_Action& action, |
| 138 | CPDFSDK_Document* pDocument, |
| 139 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 141 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 144 | visited->insert(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 147 | ASSERT(pEnv); |
| 148 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 149 | if (pEnv->IsJSInitiated()) { |
| 150 | CFX_WideString swJS = action.GetJavaScript(); |
| 151 | if (!swJS.IsEmpty()) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 152 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | pRuntime->SetReaderDocument(pDocument); |
| 154 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 155 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | pContext->OnLink_MouseUp(pDocument); |
| 157 | |
| 158 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 159 | FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | if (!bRet) { |
| 161 | // FIXME: return error. |
| 162 | } |
| 163 | |
| 164 | pRuntime->ReleaseContext(pContext); |
| 165 | } |
| 166 | } |
| 167 | } else { |
| 168 | DoAction_NoJs(action, pDocument); |
| 169 | } |
| 170 | |
| 171 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 172 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 173 | if (!ExecuteLinkAction(subaction, pDocument, visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | return FALSE; |
| 175 | } |
| 176 | |
| 177 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction( |
| 181 | const CPDF_Action& action, |
| 182 | CPDF_AAction::AActionType type, |
| 183 | CPDFSDK_Document* pDocument, |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 184 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 186 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 188 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 189 | visited->insert(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 192 | ASSERT(pEnv); |
| 193 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 194 | if (pEnv->IsJSInitiated()) { |
| 195 | CFX_WideString swJS = action.GetJavaScript(); |
| 196 | if (!swJS.IsEmpty()) { |
| 197 | RunDocumentPageJavaScript(pDocument, type, swJS); |
| 198 | } |
| 199 | } |
| 200 | } else { |
| 201 | DoAction_NoJs(action, pDocument); |
| 202 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 203 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | if (!IsValidDocView(pDocument)) |
| 205 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 208 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 209 | if (!ExecuteDocumentPageAction(subaction, type, pDocument, visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | return FALSE; |
| 211 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 212 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, |
| 217 | CPDF_Dictionary* pFieldDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 218 | ASSERT(pFieldDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 220 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 221 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
Chris Palmer | 9047b8b | 2014-08-06 14:17:45 -0700 | [diff] [blame] | 222 | return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction( |
| 226 | const CPDF_Action& action, |
| 227 | CPDF_AAction::AActionType type, |
| 228 | CPDFSDK_Document* pDocument, |
| 229 | CPDF_FormField* pFormField, |
| 230 | PDFSDK_FieldAction& data, |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 231 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 233 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 235 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 236 | visited->insert(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 239 | ASSERT(pEnv); |
| 240 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 241 | if (pEnv->IsJSInitiated()) { |
| 242 | CFX_WideString swJS = action.GetJavaScript(); |
| 243 | if (!swJS.IsEmpty()) { |
| 244 | RunFieldJavaScript(pDocument, pFormField, type, data, swJS); |
| 245 | if (!IsValidField(pDocument, pFormField->GetFieldDict())) |
| 246 | return FALSE; |
| 247 | } |
| 248 | } |
| 249 | } else { |
| 250 | DoAction_NoJs(action, pDocument); |
| 251 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 254 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 255 | if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, |
| 256 | visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | return FALSE; |
| 258 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction( |
| 264 | const CPDF_Action& action, |
| 265 | CPDF_AAction::AActionType type, |
| 266 | CPDFSDK_Document* pDocument, |
| 267 | CPDFSDK_Annot* pScreen, |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 268 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 270 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 272 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 273 | visited->insert(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 276 | ASSERT(pEnv); |
| 277 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 278 | if (pEnv->IsJSInitiated()) { |
| 279 | CFX_WideString swJS = action.GetJavaScript(); |
| 280 | if (!swJS.IsEmpty()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 281 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | pRuntime->SetReaderDocument(pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 283 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 284 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 286 | FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | if (!bRet) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 288 | // FIXME: return error. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 290 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | pRuntime->ReleaseContext(pContext); |
| 292 | } |
| 293 | } |
| 294 | } else { |
| 295 | DoAction_NoJs(action, pDocument); |
| 296 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 299 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 300 | if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | return FALSE; |
| 302 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 303 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 307 | FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark( |
| 308 | const CPDF_Action& action, |
| 309 | CPDFSDK_Document* pDocument, |
| 310 | CPDF_Bookmark* pBookmark, |
| 311 | std::set<CPDF_Dictionary*>* visited) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | CPDF_Dictionary* pDict = action.GetDict(); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 313 | if (pdfium::ContainsKey(*visited, pDict)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 315 | |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 316 | visited->insert(pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
| 319 | ASSERT(pEnv); |
| 320 | if (action.GetType() == CPDF_Action::JavaScript) { |
| 321 | if (pEnv->IsJSInitiated()) { |
| 322 | CFX_WideString swJS = action.GetJavaScript(); |
| 323 | if (!swJS.IsEmpty()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 324 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | pRuntime->SetReaderDocument(pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 326 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 327 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | pContext->OnBookmark_MouseUp(pBookmark); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 329 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 331 | FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | if (!bRet) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 333 | // FIXME: return error. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 335 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | pRuntime->ReleaseContext(pContext); |
| 337 | } |
| 338 | } |
| 339 | } else { |
| 340 | DoAction_NoJs(action, pDocument); |
| 341 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 342 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { |
| 344 | CPDF_Action subaction = action.GetSubAction(i); |
Tom Sepez | 6c7508b | 2016-01-20 14:59:25 -0800 | [diff] [blame] | 345 | if (!ExecuteBookMark(subaction, pDocument, pBookmark, visited)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | return FALSE; |
| 347 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 348 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, |
| 353 | CPDFSDK_Document* pDocument) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 354 | ASSERT(pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 355 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | switch (action.GetType()) { |
| 357 | case CPDF_Action::GoTo: |
| 358 | DoAction_GoTo(pDocument, action); |
| 359 | break; |
| 360 | case CPDF_Action::GoToR: |
| 361 | DoAction_GoToR(pDocument, action); |
| 362 | break; |
| 363 | case CPDF_Action::GoToE: |
| 364 | break; |
| 365 | case CPDF_Action::Launch: |
| 366 | DoAction_Launch(pDocument, action); |
| 367 | break; |
| 368 | case CPDF_Action::Thread: |
| 369 | break; |
| 370 | case CPDF_Action::URI: |
| 371 | DoAction_URI(pDocument, action); |
| 372 | break; |
| 373 | case CPDF_Action::Sound: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | break; |
| 375 | case CPDF_Action::Movie: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | break; |
| 377 | case CPDF_Action::Hide: |
| 378 | if (m_pFormActionHandler) { |
| 379 | m_pFormActionHandler->DoAction_Hide(action, pDocument); |
| 380 | } |
| 381 | break; |
| 382 | case CPDF_Action::Named: |
| 383 | DoAction_Named(pDocument, action); |
| 384 | break; |
| 385 | case CPDF_Action::SubmitForm: |
| 386 | if (m_pFormActionHandler) { |
| 387 | m_pFormActionHandler->DoAction_SubmitForm(action, pDocument); |
| 388 | } |
| 389 | break; |
| 390 | case CPDF_Action::ResetForm: |
| 391 | if (m_pFormActionHandler) { |
| 392 | m_pFormActionHandler->DoAction_ResetForm(action, pDocument); |
| 393 | } |
| 394 | break; |
| 395 | case CPDF_Action::ImportData: |
| 396 | if (m_pFormActionHandler) { |
| 397 | m_pFormActionHandler->DoAction_ImportData(action, pDocument); |
| 398 | } |
| 399 | break; |
| 400 | case CPDF_Action::JavaScript: |
| 401 | ASSERT(FALSE); |
| 402 | break; |
| 403 | case CPDF_Action::SetOCGState: |
| 404 | DoAction_SetOCGState(pDocument, action); |
| 405 | break; |
| 406 | case CPDF_Action::Rendition: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | break; |
| 408 | case CPDF_Action::Trans: |
| 409 | break; |
| 410 | case CPDF_Action::GoTo3DView: |
| 411 | break; |
| 412 | default: |
| 413 | break; |
| 414 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) { |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 418 | ASSERT(pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 422 | void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | const CPDF_Action& action) { |
| 424 | ASSERT(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 425 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 426 | CPDF_Document* pPDFDocument = pDocument->GetPDFDocument(); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 427 | ASSERT(pPDFDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 428 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | CPDF_Dest MyDest = action.GetDest(pPDFDocument); |
| 430 | int nPageIndex = MyDest.GetPageIndex(pPDFDocument); |
| 431 | int nFitType = MyDest.GetZoomMode(); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 432 | const CPDF_Array* pMyArray = ToArray(MyDest.GetObject()); |
| 433 | float* pPosAry = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | int sizeOfAry = 0; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 435 | if (pMyArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 436 | pPosAry = new float[pMyArray->GetCount()]; |
| 437 | int j = 0; |
| 438 | for (int i = 2; i < (int)pMyArray->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame^] | 439 | pPosAry[j++] = pMyArray->GetFloatAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | } |
| 441 | sizeOfAry = j; |
| 442 | } |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 443 | |
| 444 | CPDFDoc_Environment* pApp = pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 445 | pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry); |
Lei Zhang | da180e9 | 2015-08-14 22:22:13 -0700 | [diff] [blame] | 446 | delete[] pPosAry; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, |
| 450 | const CPDF_Action& action) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 451 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, |
| 453 | const CPDF_Action& action) {} |
| 454 | |
| 455 | void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, |
| 456 | const CPDF_Action& action) { |
| 457 | ASSERT(action); |
| 458 | |
| 459 | CPDFDoc_Environment* pApp = pDocument->GetEnv(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 460 | CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | pApp->FFI_DoURIAction(sURI.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 464 | void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, |
| 465 | const CPDF_Action& action) { |
| 466 | ASSERT(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | CFX_ByteString csName = action.GetNamedAction(); |
| 469 | pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, |
| 473 | const CPDF_Action& action) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 474 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, |
| 476 | CPDF_FormField* pFormField, |
| 477 | CPDF_AAction::AActionType type, |
| 478 | PDFSDK_FieldAction& data, |
| 479 | const CFX_WideString& script) { |
| 480 | ASSERT(type != CPDF_AAction::Calculate); |
| 481 | ASSERT(type != CPDF_AAction::Format); |
Tom Sepez | d7e5cc7 | 2015-06-10 14:33:37 -0700 | [diff] [blame] | 482 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 483 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | pRuntime->SetReaderDocument(pDocument); |
| 485 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 486 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | switch (type) { |
| 488 | case CPDF_AAction::CursorEnter: |
| 489 | pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField); |
| 490 | break; |
| 491 | case CPDF_AAction::CursorExit: |
| 492 | pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField); |
| 493 | break; |
| 494 | case CPDF_AAction::ButtonDown: |
| 495 | pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField); |
| 496 | break; |
| 497 | case CPDF_AAction::ButtonUp: |
| 498 | pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField); |
| 499 | break; |
| 500 | case CPDF_AAction::GetFocus: |
| 501 | pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, |
| 502 | data.sValue); |
| 503 | break; |
| 504 | case CPDF_AAction::LoseFocus: |
| 505 | pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, |
| 506 | data.sValue); |
| 507 | break; |
| 508 | case CPDF_AAction::KeyStroke: |
| 509 | pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown, |
| 510 | data.bModifier, data.nSelEnd, data.nSelStart, |
| 511 | data.bShift, pFormField, data.sValue, |
| 512 | data.bWillCommit, data.bFieldFull, data.bRC); |
| 513 | break; |
| 514 | case CPDF_AAction::Validate: |
| 515 | pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, |
| 516 | data.bModifier, data.bShift, pFormField, |
| 517 | data.sValue, data.bRC); |
| 518 | break; |
| 519 | default: |
| 520 | ASSERT(FALSE); |
| 521 | break; |
| 522 | } |
| 523 | |
| 524 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 525 | FX_BOOL bRet = pContext->RunScript(script, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 526 | if (!bRet) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 527 | // FIXME: return error. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 533 | void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript( |
| 534 | CPDFSDK_Document* pDocument, |
| 535 | const CFX_WideString& sScriptName, |
| 536 | const CFX_WideString& script) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 537 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | pRuntime->SetReaderDocument(pDocument); |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 539 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | pContext->OnDoc_Open(pDocument, sScriptName); |
| 541 | |
| 542 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 543 | FX_BOOL bRet = pContext->RunScript(script, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | if (!bRet) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 545 | // FIXME: return error. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 551 | void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( |
| 552 | CPDFSDK_Document* pDocument, |
| 553 | CPDF_AAction::AActionType type, |
| 554 | const CFX_WideString& script) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 555 | IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | pRuntime->SetReaderDocument(pDocument); |
| 557 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 558 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | switch (type) { |
| 560 | case CPDF_AAction::OpenPage: |
| 561 | pContext->OnPage_Open(pDocument); |
| 562 | break; |
| 563 | case CPDF_AAction::ClosePage: |
| 564 | pContext->OnPage_Close(pDocument); |
| 565 | break; |
| 566 | case CPDF_AAction::CloseDocument: |
| 567 | pContext->OnDoc_WillClose(pDocument); |
| 568 | break; |
| 569 | case CPDF_AAction::SaveDocument: |
| 570 | pContext->OnDoc_WillSave(pDocument); |
| 571 | break; |
| 572 | case CPDF_AAction::DocumentSaved: |
| 573 | pContext->OnDoc_DidSave(pDocument); |
| 574 | break; |
| 575 | case CPDF_AAction::PrintDocument: |
| 576 | pContext->OnDoc_WillPrint(pDocument); |
| 577 | break; |
| 578 | case CPDF_AAction::DocumentPrinted: |
| 579 | pContext->OnDoc_DidPrint(pDocument); |
| 580 | break; |
| 581 | case CPDF_AAction::PageVisible: |
| 582 | pContext->OnPage_InView(pDocument); |
| 583 | break; |
| 584 | case CPDF_AAction::PageInvisible: |
| 585 | pContext->OnPage_OutView(pDocument); |
| 586 | break; |
| 587 | default: |
| 588 | ASSERT(FALSE); |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | CFX_WideString csInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 593 | FX_BOOL bRet = pContext->RunScript(script, &csInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | if (!bRet) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 595 | // FIXME: return error. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, |
| 602 | CPDFSDK_Document* pDocument) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | if (pInterForm->DoAction_Hide(action)) { |
| 605 | pDocument->SetChangeMark(); |
| 606 | return TRUE; |
| 607 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 608 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm( |
| 613 | const CPDF_Action& action, |
| 614 | CPDFSDK_Document* pDocument) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 615 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 616 | return pInterForm->DoAction_SubmitForm(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 619 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm( |
| 620 | const CPDF_Action& action, |
| 621 | CPDFSDK_Document* pDocument) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 623 | return pInterForm->DoAction_ResetForm(action); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData( |
| 627 | const CPDF_Action& action, |
| 628 | CPDFSDK_Document* pDocument) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | if (pInterForm->DoAction_ImportData(action)) { |
| 631 | pDocument->SetChangeMark(); |
| 632 | return TRUE; |
| 633 | } |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 634 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 636 | } |