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