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

Side by Side Diff: fpdfsdk/javascript/app.cpp

Issue 2399943002: Remove CPDFSDK_Document from IJS_Context (Closed)
Patch Set: Rebase to master Created 4 years, 2 months 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
« no previous file with comments | « fpdfsdk/javascript/PublicMethods.cpp ('k') | fpdfsdk/javascript/cjs_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/javascript/app.h" 7 #include "fpdfsdk/javascript/app.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 app::~app() { 210 app::~app() {
211 } 211 }
212 212
213 FX_BOOL app::activeDocs(IJS_Context* cc, 213 FX_BOOL app::activeDocs(IJS_Context* cc,
214 CJS_PropValue& vp, 214 CJS_PropValue& vp,
215 CFX_WideString& sError) { 215 CFX_WideString& sError) {
216 if (!vp.IsGetting()) 216 if (!vp.IsGetting())
217 return FALSE; 217 return FALSE;
218 218
219 CJS_Context* pContext = (CJS_Context*)cc; 219 CJS_Context* pContext = (CJS_Context*)cc;
220 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetReaderEnv(); 220 CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv();
221 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 221 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
222 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); 222 CPDFSDK_Document* pCurDoc = pContext->GetJSRuntime()->GetReaderDocument();
223 CJS_Array aDocs; 223 CJS_Array aDocs;
224 if (CPDFSDK_Document* pDoc = pEnv->GetSDKDocument()) { 224 if (CPDFSDK_Document* pDoc = pFormFillEnv->GetSDKDocument()) {
225 CJS_Document* pJSDocument = nullptr; 225 CJS_Document* pJSDocument = nullptr;
226 if (pDoc == pCurDoc) { 226 if (pDoc == pCurDoc) {
227 v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); 227 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
228 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { 228 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) {
229 pJSDocument = 229 pJSDocument =
230 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); 230 static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
231 } 231 }
232 } else { 232 } else {
233 v8::Local<v8::Object> pObj = 233 v8::Local<v8::Object> pObj =
234 pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID); 234 pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID);
(...skipping 13 matching lines...) Expand all
248 248
249 FX_BOOL app::calculate(IJS_Context* cc, 249 FX_BOOL app::calculate(IJS_Context* cc,
250 CJS_PropValue& vp, 250 CJS_PropValue& vp,
251 CFX_WideString& sError) { 251 CFX_WideString& sError) {
252 if (vp.IsSetting()) { 252 if (vp.IsSetting()) {
253 bool bVP; 253 bool bVP;
254 vp >> bVP; 254 vp >> bVP;
255 m_bCalculate = (FX_BOOL)bVP; 255 m_bCalculate = (FX_BOOL)bVP;
256 256
257 CJS_Context* pContext = (CJS_Context*)cc; 257 CJS_Context* pContext = (CJS_Context*)cc;
258 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetReaderEnv(); 258 pContext->GetFormFillEnv()
259 if (CPDFSDK_Document* pDoc = pEnv->GetSDKDocument()) 259 ->GetSDKDocument()
260 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); 260 ->GetInterForm()
261 ->EnableCalculate((FX_BOOL)m_bCalculate);
261 } else { 262 } else {
262 vp << (bool)m_bCalculate; 263 vp << (bool)m_bCalculate;
263 } 264 }
264 return TRUE; 265 return TRUE;
265 } 266 }
266 267
267 FX_BOOL app::formsVersion(IJS_Context* cc, 268 FX_BOOL app::formsVersion(IJS_Context* cc,
268 CJS_PropValue& vp, 269 CJS_PropValue& vp,
269 CFX_WideString& sError) { 270 CFX_WideString& sError) {
270 if (vp.IsGetting()) { 271 if (vp.IsGetting()) {
(...skipping 26 matching lines...) Expand all
297 return FALSE; 298 return FALSE;
298 } 299 }
299 300
300 FX_BOOL app::viewerVersion(IJS_Context* cc, 301 FX_BOOL app::viewerVersion(IJS_Context* cc,
301 CJS_PropValue& vp, 302 CJS_PropValue& vp,
302 CFX_WideString& sError) { 303 CFX_WideString& sError) {
303 if (!vp.IsGetting()) 304 if (!vp.IsGetting())
304 return FALSE; 305 return FALSE;
305 #ifdef PDF_ENABLE_XFA 306 #ifdef PDF_ENABLE_XFA
306 CJS_Context* pContext = (CJS_Context*)cc; 307 CJS_Context* pContext = (CJS_Context*)cc;
307 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); 308 CPDFXFA_Document* pDoc =
308 CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument(); 309 pContext->GetFormFillEnv()->GetSDKDocument()->GetXFADocument();
309 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) { 310 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
310 vp << JS_NUM_VIEWERVERSION_XFA; 311 vp << JS_NUM_VIEWERVERSION_XFA;
311 return TRUE; 312 return TRUE;
312 } 313 }
313 #endif // PDF_ENABLE_XFA 314 #endif // PDF_ENABLE_XFA
314 vp << JS_NUM_VIEWERVERSION; 315 vp << JS_NUM_VIEWERVERSION;
315 return TRUE; 316 return TRUE;
316 } 317 }
317 318
318 FX_BOOL app::platform(IJS_Context* cc, 319 FX_BOOL app::platform(IJS_Context* cc,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 if (newParams[2].GetType() != CJS_Value::VT_unknown) 427 if (newParams[2].GetType() != CJS_Value::VT_unknown)
427 iType = newParams[2].ToInt(pRuntime); 428 iType = newParams[2].ToInt(pRuntime);
428 429
429 CFX_WideString swTitle; 430 CFX_WideString swTitle;
430 if (newParams[3].GetType() != CJS_Value::VT_unknown) 431 if (newParams[3].GetType() != CJS_Value::VT_unknown)
431 swTitle = newParams[3].ToCFXWideString(pRuntime); 432 swTitle = newParams[3].ToCFXWideString(pRuntime);
432 else 433 else
433 swTitle = JSGetStringFromID(IDS_STRING_JSALERT); 434 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
434 435
435 pRuntime->BeginBlock(); 436 pRuntime->BeginBlock();
436 if (CPDFSDK_Document* pDoc = pEnv->GetSDKDocument()) 437 pEnv->GetSDKDocument()->KillFocusAnnot(0);
437 pDoc->KillFocusAnnot(0);
438 438
439 vRet = CJS_Value(pRuntime, pEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), 439 vRet = CJS_Value(pRuntime, pEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(),
440 iType, iIcon)); 440 iType, iIcon));
441 pRuntime->EndBlock(); 441 pRuntime->EndBlock();
442 return TRUE; 442 return TRUE;
443 } 443 }
444 444
445 FX_BOOL app::beep(IJS_Context* cc, 445 FX_BOOL app::beep(IJS_Context* cc,
446 const std::vector<CJS_Value>& params, 446 const std::vector<CJS_Value>& params,
447 CJS_Value& vRet, 447 CJS_Value& vRet,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 CFX_WideString cSubject; 671 CFX_WideString cSubject;
672 if (newParams[4].GetType() != CJS_Value::VT_unknown) 672 if (newParams[4].GetType() != CJS_Value::VT_unknown)
673 cSubject = newParams[4].ToCFXWideString(pRuntime); 673 cSubject = newParams[4].ToCFXWideString(pRuntime);
674 674
675 CFX_WideString cMsg; 675 CFX_WideString cMsg;
676 if (newParams[5].GetType() != CJS_Value::VT_unknown) 676 if (newParams[5].GetType() != CJS_Value::VT_unknown)
677 cMsg = newParams[5].ToCFXWideString(pRuntime); 677 cMsg = newParams[5].ToCFXWideString(pRuntime);
678 678
679 pRuntime->BeginBlock(); 679 pRuntime->BeginBlock();
680 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 680 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
681 pContext->GetReaderEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), 681 pContext->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
682 cSubject.c_str(), cCc.c_str(), 682 cSubject.c_str(), cCc.c_str(),
683 cBcc.c_str(), cMsg.c_str()); 683 cBcc.c_str(), cMsg.c_str());
684 pRuntime->EndBlock(); 684 pRuntime->EndBlock();
685 return TRUE; 685 return TRUE;
686 } 686 }
687 687
688 FX_BOOL app::launchURL(IJS_Context* cc, 688 FX_BOOL app::launchURL(IJS_Context* cc,
689 const std::vector<CJS_Value>& params, 689 const std::vector<CJS_Value>& params,
690 CJS_Value& vRet, 690 CJS_Value& vRet,
691 CFX_WideString& sError) { 691 CFX_WideString& sError) {
692 // Unsafe, not supported. 692 // Unsafe, not supported.
693 return TRUE; 693 return TRUE;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 786
787 CFX_WideString swLabel; 787 CFX_WideString swLabel;
788 if (newParams[4].GetType() != CJS_Value::VT_unknown) 788 if (newParams[4].GetType() != CJS_Value::VT_unknown)
789 swLabel = newParams[4].ToCFXWideString(pRuntime); 789 swLabel = newParams[4].ToCFXWideString(pRuntime);
790 790
791 const int MAX_INPUT_BYTES = 2048; 791 const int MAX_INPUT_BYTES = 2048;
792 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); 792 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
793 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); 793 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
794 794
795 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 795 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
796 int nLengthBytes = pContext->GetReaderEnv()->JS_appResponse( 796 int nLengthBytes = pContext->GetFormFillEnv()->JS_appResponse(
797 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), 797 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
798 bPassword, pBuff.get(), MAX_INPUT_BYTES); 798 bPassword, pBuff.get(), MAX_INPUT_BYTES);
799 799
800 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { 800 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
801 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); 801 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
802 return FALSE; 802 return FALSE;
803 } 803 }
804 804
805 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( 805 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE(
806 reinterpret_cast<uint16_t*>(pBuff.get()), 806 reinterpret_cast<uint16_t*>(pBuff.get()),
807 nLengthBytes / sizeof(uint16_t)) 807 nLengthBytes / sizeof(uint16_t))
808 .c_str()); 808 .c_str());
809 809
810 return TRUE; 810 return TRUE;
811 } 811 }
812 812
813 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { 813 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
814 return FALSE; 814 return FALSE;
815 } 815 }
816 816
817 FX_BOOL app::execDialog(IJS_Context* cc, 817 FX_BOOL app::execDialog(IJS_Context* cc,
818 const std::vector<CJS_Value>& params, 818 const std::vector<CJS_Value>& params,
819 CJS_Value& vRet, 819 CJS_Value& vRet,
820 CFX_WideString& sError) { 820 CFX_WideString& sError) {
821 return TRUE; 821 return TRUE;
822 } 822 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/PublicMethods.cpp ('k') | fpdfsdk/javascript/cjs_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698