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