Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: fpdfsdk/src/fsdk_actionhandler.cpp

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/include/fsdk_actionhandler.h" 7 #include "fpdfsdk/include/fsdk_actionhandler.h"
8 #include "fpdfsdk/include/fsdk_define.h" 8 #include "fpdfsdk/include/fsdk_define.h"
9 #include "fpdfsdk/include/fsdk_mgr.h" 9 #include "fpdfsdk/include/fsdk_mgr.h"
10 #include "fpdfsdk/include/javascript/IJavaScript.h" 10 #include "fpdfsdk/include/javascript/IJavaScript.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (!ExecuteDocumentOpenAction(subaction, pDocument, list)) 127 if (!ExecuteDocumentOpenAction(subaction, pDocument, list))
128 return FALSE; 128 return FALSE;
129 } 129 }
130 130
131 return TRUE; 131 return TRUE;
132 } 132 }
133 133
134 FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, 134 FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,
135 CPDFSDK_Document* pDocument, 135 CPDFSDK_Document* pDocument,
136 CFX_PtrList& list) { 136 CFX_PtrList& list) {
137 ASSERT(pDocument != NULL);
138
139 CPDF_Dictionary* pDict = action.GetDict(); 137 CPDF_Dictionary* pDict = action.GetDict();
140 if (list.Find(pDict)) 138 if (list.Find(pDict))
141 return FALSE; 139 return FALSE;
142 140
143 list.AddTail(pDict); 141 list.AddTail(pDict);
144 142
145 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 143 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
146 ASSERT(pEnv); 144 ASSERT(pEnv);
147 if (action.GetType() == CPDF_Action::JavaScript) { 145 if (action.GetType() == CPDF_Action::JavaScript) {
148 if (pEnv->IsJSInitiated()) { 146 if (pEnv->IsJSInitiated()) {
(...skipping 25 matching lines...) Expand all
174 } 172 }
175 173
176 return TRUE; 174 return TRUE;
177 } 175 }
178 176
179 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction( 177 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
180 const CPDF_Action& action, 178 const CPDF_Action& action,
181 CPDF_AAction::AActionType type, 179 CPDF_AAction::AActionType type,
182 CPDFSDK_Document* pDocument, 180 CPDFSDK_Document* pDocument,
183 CFX_PtrList& list) { 181 CFX_PtrList& list) {
184 ASSERT(pDocument != NULL);
185
186 CPDF_Dictionary* pDict = action.GetDict(); 182 CPDF_Dictionary* pDict = action.GetDict();
187 if (list.Find(pDict)) 183 if (list.Find(pDict))
188 return FALSE; 184 return FALSE;
189 185
190 list.AddTail(pDict); 186 list.AddTail(pDict);
191 187
192 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 188 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
193 ASSERT(pEnv); 189 ASSERT(pEnv);
194 if (action.GetType() == CPDF_Action::JavaScript) { 190 if (action.GetType() == CPDF_Action::JavaScript) {
195 if (pEnv->IsJSInitiated()) { 191 if (pEnv->IsJSInitiated()) {
(...skipping 13 matching lines...) Expand all
209 CPDF_Action subaction = action.GetSubAction(i); 205 CPDF_Action subaction = action.GetSubAction(i);
210 if (!ExecuteDocumentPageAction(subaction, type, pDocument, list)) 206 if (!ExecuteDocumentPageAction(subaction, type, pDocument, list))
211 return FALSE; 207 return FALSE;
212 } 208 }
213 209
214 return TRUE; 210 return TRUE;
215 } 211 }
216 212
217 FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, 213 FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument,
218 CPDF_Dictionary* pFieldDict) { 214 CPDF_Dictionary* pFieldDict) {
219 ASSERT(pDocument != NULL); 215 ASSERT(pFieldDict);
220 ASSERT(pFieldDict != NULL);
221 216
222 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); 217 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
223 ASSERT(pInterForm != NULL);
224
225 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 218 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
226 ASSERT(pPDFInterForm != NULL);
227
228 return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL; 219 return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
229 } 220 }
230 221
231 FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction( 222 FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(
232 const CPDF_Action& action, 223 const CPDF_Action& action,
233 CPDF_AAction::AActionType type, 224 CPDF_AAction::AActionType type,
234 CPDFSDK_Document* pDocument, 225 CPDFSDK_Document* pDocument,
235 CPDF_FormField* pFormField, 226 CPDF_FormField* pFormField,
236 PDFSDK_FieldAction& data, 227 PDFSDK_FieldAction& data,
237 CFX_PtrList& list) { 228 CFX_PtrList& list) {
238 ASSERT(pDocument != NULL);
239
240 CPDF_Dictionary* pDict = action.GetDict(); 229 CPDF_Dictionary* pDict = action.GetDict();
241 if (list.Find(pDict)) 230 if (list.Find(pDict))
242 return FALSE; 231 return FALSE;
243 232
244 list.AddTail(pDict); 233 list.AddTail(pDict);
245 234
246 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 235 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
247 ASSERT(pEnv); 236 ASSERT(pEnv);
248 if (action.GetType() == CPDF_Action::JavaScript) { 237 if (action.GetType() == CPDF_Action::JavaScript) {
249 if (pEnv->IsJSInitiated()) { 238 if (pEnv->IsJSInitiated()) {
(...skipping 16 matching lines...) Expand all
266 255
267 return TRUE; 256 return TRUE;
268 } 257 }
269 258
270 FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction( 259 FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(
271 const CPDF_Action& action, 260 const CPDF_Action& action,
272 CPDF_AAction::AActionType type, 261 CPDF_AAction::AActionType type,
273 CPDFSDK_Document* pDocument, 262 CPDFSDK_Document* pDocument,
274 CPDFSDK_Annot* pScreen, 263 CPDFSDK_Annot* pScreen,
275 CFX_PtrList& list) { 264 CFX_PtrList& list) {
276 ASSERT(pDocument != NULL);
277
278 CPDF_Dictionary* pDict = action.GetDict(); 265 CPDF_Dictionary* pDict = action.GetDict();
279 if (list.Find(pDict)) 266 if (list.Find(pDict))
280 return FALSE; 267 return FALSE;
281 268
282 list.AddTail(pDict); 269 list.AddTail(pDict);
283 270
284 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 271 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
285 ASSERT(pEnv); 272 ASSERT(pEnv);
286 if (action.GetType() == CPDF_Action::JavaScript) { 273 if (action.GetType() == CPDF_Action::JavaScript) {
287 if (pEnv->IsJSInitiated()) { 274 if (pEnv->IsJSInitiated()) {
(...skipping 22 matching lines...) Expand all
310 return FALSE; 297 return FALSE;
311 } 298 }
312 299
313 return TRUE; 300 return TRUE;
314 } 301 }
315 302
316 FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, 303 FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action,
317 CPDFSDK_Document* pDocument, 304 CPDFSDK_Document* pDocument,
318 CPDF_Bookmark* pBookmark, 305 CPDF_Bookmark* pBookmark,
319 CFX_PtrList& list) { 306 CFX_PtrList& list) {
320 ASSERT(pDocument != NULL);
321
322 CPDF_Dictionary* pDict = action.GetDict(); 307 CPDF_Dictionary* pDict = action.GetDict();
323 if (list.Find(pDict)) 308 if (list.Find(pDict))
324 return FALSE; 309 return FALSE;
325 310
326 list.AddTail(pDict); 311 list.AddTail(pDict);
327 312
328 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 313 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
329 ASSERT(pEnv); 314 ASSERT(pEnv);
330 if (action.GetType() == CPDF_Action::JavaScript) { 315 if (action.GetType() == CPDF_Action::JavaScript) {
331 if (pEnv->IsJSInitiated()) { 316 if (pEnv->IsJSInitiated()) {
(...skipping 22 matching lines...) Expand all
354 CPDF_Action subaction = action.GetSubAction(i); 339 CPDF_Action subaction = action.GetSubAction(i);
355 if (!ExecuteBookMark(subaction, pDocument, pBookmark, list)) 340 if (!ExecuteBookMark(subaction, pDocument, pBookmark, list))
356 return FALSE; 341 return FALSE;
357 } 342 }
358 343
359 return TRUE; 344 return TRUE;
360 } 345 }
361 346
362 void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, 347 void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action,
363 CPDFSDK_Document* pDocument) { 348 CPDFSDK_Document* pDocument) {
364 ASSERT(pDocument != NULL); 349 ASSERT(pDocument);
365 350
366 switch (action.GetType()) { 351 switch (action.GetType()) {
367 case CPDF_Action::GoTo: 352 case CPDF_Action::GoTo:
368 DoAction_GoTo(pDocument, action); 353 DoAction_GoTo(pDocument, action);
369 break; 354 break;
370 case CPDF_Action::GoToR: 355 case CPDF_Action::GoToR:
371 DoAction_GoToR(pDocument, action); 356 DoAction_GoToR(pDocument, action);
372 break; 357 break;
373 case CPDF_Action::GoToE: 358 case CPDF_Action::GoToE:
374 break; 359 break;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 const CPDF_Action& action) {} 445 const CPDF_Action& action) {}
461 446
462 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, 447 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
463 const CPDF_Action& action) {} 448 const CPDF_Action& action) {}
464 449
465 void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, 450 void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument,
466 const CPDF_Action& action) { 451 const CPDF_Action& action) {
467 ASSERT(action); 452 ASSERT(action);
468 453
469 CPDFDoc_Environment* pApp = pDocument->GetEnv(); 454 CPDFDoc_Environment* pApp = pDocument->GetEnv();
470 ASSERT(pApp != NULL);
471
472 CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument()); 455 CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument());
473 pApp->FFI_DoURIAction(sURI.c_str()); 456 pApp->FFI_DoURIAction(sURI.c_str());
474 } 457 }
475 458
476 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, 459 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
477 const CPDF_Action& action) { 460 const CPDF_Action& action) {
478 ASSERT(action); 461 ASSERT(action);
479 462
480 CFX_ByteString csName = action.GetNamedAction(); 463 CFX_ByteString csName = action.GetNamedAction();
481 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); 464 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
482 } 465 }
483 466
484 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, 467 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
485 const CPDF_Action& action) {} 468 const CPDF_Action& action) {}
486 469
487 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, 470 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
488 CPDF_FormField* pFormField, 471 CPDF_FormField* pFormField,
489 CPDF_AAction::AActionType type, 472 CPDF_AAction::AActionType type,
490 PDFSDK_FieldAction& data, 473 PDFSDK_FieldAction& data,
491 const CFX_WideString& script) { 474 const CFX_WideString& script) {
492 ASSERT(type != CPDF_AAction::Calculate); 475 ASSERT(type != CPDF_AAction::Calculate);
493 ASSERT(type != CPDF_AAction::Format); 476 ASSERT(type != CPDF_AAction::Format);
494 477
495 ASSERT(pDocument != NULL);
496
497 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 478 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
498 ASSERT(pRuntime != NULL);
499
500 pRuntime->SetReaderDocument(pDocument); 479 pRuntime->SetReaderDocument(pDocument);
501 480
502 IJS_Context* pContext = pRuntime->NewContext(); 481 IJS_Context* pContext = pRuntime->NewContext();
503 ASSERT(pContext != NULL);
504
505 switch (type) { 482 switch (type) {
506 case CPDF_AAction::CursorEnter: 483 case CPDF_AAction::CursorEnter:
507 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField); 484 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
508 break; 485 break;
509 case CPDF_AAction::CursorExit: 486 case CPDF_AAction::CursorExit:
510 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField); 487 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
511 break; 488 break;
512 case CPDF_AAction::ButtonDown: 489 case CPDF_AAction::ButtonDown:
513 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField); 490 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
514 break; 491 break;
(...skipping 30 matching lines...) Expand all
545 // FIXME: return error. 522 // FIXME: return error.
546 } 523 }
547 524
548 pRuntime->ReleaseContext(pContext); 525 pRuntime->ReleaseContext(pContext);
549 } 526 }
550 527
551 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript( 528 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
552 CPDFSDK_Document* pDocument, 529 CPDFSDK_Document* pDocument,
553 const CFX_WideString& sScriptName, 530 const CFX_WideString& sScriptName,
554 const CFX_WideString& script) { 531 const CFX_WideString& script) {
555 ASSERT(pDocument != NULL);
556
557 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 532 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
558 ASSERT(pRuntime != NULL);
559
560 pRuntime->SetReaderDocument(pDocument); 533 pRuntime->SetReaderDocument(pDocument);
561
562 IJS_Context* pContext = pRuntime->NewContext(); 534 IJS_Context* pContext = pRuntime->NewContext();
563 ASSERT(pContext != NULL);
564
565 pContext->OnDoc_Open(pDocument, sScriptName); 535 pContext->OnDoc_Open(pDocument, sScriptName);
566 536
567 CFX_WideString csInfo; 537 CFX_WideString csInfo;
568 FX_BOOL bRet = pContext->RunScript(script, &csInfo); 538 FX_BOOL bRet = pContext->RunScript(script, &csInfo);
569 if (!bRet) { 539 if (!bRet) {
570 // FIXME: return error. 540 // FIXME: return error.
571 } 541 }
572 542
573 pRuntime->ReleaseContext(pContext); 543 pRuntime->ReleaseContext(pContext);
574 } 544 }
575 545
576 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( 546 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
577 CPDFSDK_Document* pDocument, 547 CPDFSDK_Document* pDocument,
578 CPDF_AAction::AActionType type, 548 CPDF_AAction::AActionType type,
579 const CFX_WideString& script) { 549 const CFX_WideString& script) {
580 ASSERT(pDocument != NULL);
581
582 IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 550 IJS_Runtime* pRuntime = pDocument->GetJsRuntime();
583 ASSERT(pRuntime != NULL);
584
585 pRuntime->SetReaderDocument(pDocument); 551 pRuntime->SetReaderDocument(pDocument);
586 552
587 IJS_Context* pContext = pRuntime->NewContext(); 553 IJS_Context* pContext = pRuntime->NewContext();
588 ASSERT(pContext != NULL);
589
590 switch (type) { 554 switch (type) {
591 case CPDF_AAction::OpenPage: 555 case CPDF_AAction::OpenPage:
592 pContext->OnPage_Open(pDocument); 556 pContext->OnPage_Open(pDocument);
593 break; 557 break;
594 case CPDF_AAction::ClosePage: 558 case CPDF_AAction::ClosePage:
595 pContext->OnPage_Close(pDocument); 559 pContext->OnPage_Close(pDocument);
596 break; 560 break;
597 case CPDF_AAction::CloseDocument: 561 case CPDF_AAction::CloseDocument:
598 pContext->OnDoc_WillClose(pDocument); 562 pContext->OnDoc_WillClose(pDocument);
599 break; 563 break;
(...skipping 24 matching lines...) Expand all
624 FX_BOOL bRet = pContext->RunScript(script, &csInfo); 588 FX_BOOL bRet = pContext->RunScript(script, &csInfo);
625 if (!bRet) { 589 if (!bRet) {
626 // FIXME: return error. 590 // FIXME: return error.
627 } 591 }
628 592
629 pRuntime->ReleaseContext(pContext); 593 pRuntime->ReleaseContext(pContext);
630 } 594 }
631 595
632 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, 596 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
633 CPDFSDK_Document* pDocument) { 597 CPDFSDK_Document* pDocument) {
634 ASSERT(pDocument != NULL);
635
636 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 598 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
637 ASSERT(pInterForm != NULL);
638
639 if (pInterForm->DoAction_Hide(action)) { 599 if (pInterForm->DoAction_Hide(action)) {
640 pDocument->SetChangeMark(); 600 pDocument->SetChangeMark();
641 return TRUE; 601 return TRUE;
642 } 602 }
643 603
644 return FALSE; 604 return FALSE;
645 } 605 }
646 606
647 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm( 607 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
648 const CPDF_Action& action, 608 const CPDF_Action& action,
649 CPDFSDK_Document* pDocument) { 609 CPDFSDK_Document* pDocument) {
650 ASSERT(pDocument != NULL);
651
652 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 610 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
653 ASSERT(pInterForm != NULL);
654
655 return pInterForm->DoAction_SubmitForm(action); 611 return pInterForm->DoAction_SubmitForm(action);
656 } 612 }
657 613
658 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm( 614 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
659 const CPDF_Action& action, 615 const CPDF_Action& action,
660 CPDFSDK_Document* pDocument) { 616 CPDFSDK_Document* pDocument) {
661 ASSERT(pDocument != NULL);
662
663 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 617 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
664 ASSERT(pInterForm != NULL); 618 return pInterForm->DoAction_ResetForm(action);
665
666 if (pInterForm->DoAction_ResetForm(action)) {
667 return TRUE;
668 }
669
670 return FALSE;
671 } 619 }
672 620
673 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData( 621 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
674 const CPDF_Action& action, 622 const CPDF_Action& action,
675 CPDFSDK_Document* pDocument) { 623 CPDFSDK_Document* pDocument) {
676 ASSERT(pDocument != NULL);
677
678 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 624 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
679 ASSERT(pInterForm != NULL);
680
681 if (pInterForm->DoAction_ImportData(action)) { 625 if (pInterForm->DoAction_ImportData(action)) {
682 pDocument->SetChangeMark(); 626 pDocument->SetChangeMark();
683 return TRUE; 627 return TRUE;
684 } 628 }
685 629
686 return FALSE; 630 return FALSE;
687 } 631 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698