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

Side by Side Diff: fpdfsdk/src/javascript/app.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 "app.h" 7 #include "app.h"
8 8
9 #include "Document.h" 9 #include "Document.h"
10 #include "JS_Context.h" 10 #include "JS_Context.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (pDoc == pCurDoc) { 122 if (pDoc == pCurDoc) {
123 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); 123 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
124 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) 124 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
125 pJSDocument = 125 pJSDocument =
126 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 126 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
127 } else { 127 } else {
128 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 128 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
129 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); 129 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
130 pJSDocument = 130 pJSDocument =
131 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 131 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
132 ASSERT(pJSDocument != NULL); 132 ASSERT(pJSDocument);
133 } 133 }
134 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument)); 134 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
135 } 135 }
136 if (aDocs.GetLength() > 0) 136 if (aDocs.GetLength() > 0)
137 vp << aDocs; 137 vp << aDocs;
138 else 138 else
139 vp.SetNull(); 139 vp.SetNull();
140 140
141 return TRUE; 141 return TRUE;
142 } 142 }
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 FX_BOOL app::setTimeOut(IJS_Context* cc, 443 FX_BOOL app::setTimeOut(IJS_Context* cc,
444 const std::vector<CJS_Value>& params, 444 const std::vector<CJS_Value>& params,
445 CJS_Value& vRet, 445 CJS_Value& vRet,
446 CFX_WideString& sError) { 446 CFX_WideString& sError) {
447 if (params.size() > 2 || params.size() == 0) { 447 if (params.size() > 2 || params.size() == 0) {
448 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 448 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
449 return FALSE; 449 return FALSE;
450 } 450 }
451 451
452 CJS_Context* pContext = (CJS_Context*)cc; 452 CJS_Context* pContext = (CJS_Context*)cc;
453 ASSERT(pContext != NULL);
454 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 453 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
455 ASSERT(pRuntime != NULL);
456 454
457 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; 455 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
458 if (script.IsEmpty()) { 456 if (script.IsEmpty()) {
459 sError = 457 sError =
460 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); 458 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
461 return TRUE; 459 return TRUE;
462 } 460 }
463 461
464 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; 462 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
465 463
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 552 }
555 553
556 FX_BOOL app::execMenuItem(IJS_Context* cc, 554 FX_BOOL app::execMenuItem(IJS_Context* cc,
557 const std::vector<CJS_Value>& params, 555 const std::vector<CJS_Value>& params,
558 CJS_Value& vRet, 556 CJS_Value& vRet,
559 CFX_WideString& sError) { 557 CFX_WideString& sError) {
560 return FALSE; 558 return FALSE;
561 } 559 }
562 560
563 void app::TimerProc(CJS_Timer* pTimer) { 561 void app::TimerProc(CJS_Timer* pTimer) {
564 ASSERT(pTimer != NULL);
565
566 CJS_Runtime* pRuntime = pTimer->GetRuntime(); 562 CJS_Runtime* pRuntime = pTimer->GetRuntime();
567 563
568 switch (pTimer->GetType()) { 564 switch (pTimer->GetType()) {
569 case 0: // interval 565 case 0: // interval
570 if (pRuntime) 566 if (pRuntime)
571 RunJsScript(pRuntime, pTimer->GetJScript()); 567 RunJsScript(pRuntime, pTimer->GetJScript());
572 break; 568 break;
573 case 1: 569 case 1:
574 if (pTimer->GetTimeOut() > 0) { 570 if (pTimer->GetTimeOut() > 0) {
575 if (pRuntime) 571 if (pRuntime)
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // FALLTHROUGH 793 // FALLTHROUGH
798 case 1: 794 case 1:
799 swQuestion = params[0].ToCFXWideString(); 795 swQuestion = params[0].ToCFXWideString();
800 // FALLTHROUGH 796 // FALLTHROUGH
801 default: 797 default:
802 break; 798 break;
803 } 799 }
804 } 800 }
805 801
806 CJS_Context* pContext = (CJS_Context*)cc; 802 CJS_Context* pContext = (CJS_Context*)cc;
807 ASSERT(pContext != NULL);
808
809 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 803 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
810 ASSERT(pApp != NULL);
811 804
812 const int MAX_INPUT_BYTES = 2048; 805 const int MAX_INPUT_BYTES = 2048;
813 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); 806 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
814 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); 807 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
815 int nLengthBytes = pApp->JS_appResponse( 808 int nLengthBytes = pApp->JS_appResponse(
816 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), 809 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
817 bPassWord, pBuff.get(), MAX_INPUT_BYTES); 810 bPassWord, pBuff.get(), MAX_INPUT_BYTES);
818 if (nLengthBytes <= 0) { 811 if (nLengthBytes <= 0) {
819 vRet.SetNull(); 812 vRet.SetNull();
820 return FALSE; 813 return FALSE;
821 } 814 }
822 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); 815 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
823 816
824 CFX_WideString ret_string = CFX_WideString::FromUTF16LE( 817 CFX_WideString ret_string = CFX_WideString::FromUTF16LE(
825 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short)); 818 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short));
826 vRet = ret_string.c_str(); 819 vRet = ret_string.c_str();
827 return TRUE; 820 return TRUE;
828 } 821 }
829 822
830 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { 823 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
831 return FALSE; 824 return FALSE;
832 } 825 }
833 826
834 FX_BOOL app::execDialog(IJS_Context* cc, 827 FX_BOOL app::execDialog(IJS_Context* cc,
835 const std::vector<CJS_Value>& params, 828 const std::vector<CJS_Value>& params,
836 CJS_Value& vRet, 829 CJS_Value& vRet,
837 CFX_WideString& sError) { 830 CFX_WideString& sError) {
838 return TRUE; 831 return TRUE;
839 } 832 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698