| OLD | NEW |
| 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/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 CJS_PropValue& vp, | 166 CJS_PropValue& vp, |
| 167 CFX_WideString& sError) { | 167 CFX_WideString& sError) { |
| 168 if (vp.IsSetting()) { | 168 if (vp.IsSetting()) { |
| 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 170 return FALSE; | 170 return FALSE; |
| 171 } | 171 } |
| 172 if (!m_pDocument) { | 172 if (!m_pDocument) { |
| 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 174 return FALSE; | 174 return FALSE; |
| 175 } | 175 } |
| 176 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 176 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 178 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); | 178 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); |
| 179 return TRUE; | 179 return TRUE; |
| 180 } | 180 } |
| 181 | 181 |
| 182 FX_BOOL Document::dirty(IJS_Context* cc, | 182 FX_BOOL Document::dirty(IJS_Context* cc, |
| 183 CJS_PropValue& vp, | 183 CJS_PropValue& vp, |
| 184 CFX_WideString& sError) { | 184 CFX_WideString& sError) { |
| 185 if (!m_pDocument) { | 185 if (!m_pDocument) { |
| 186 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 186 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 291 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 292 return FALSE; | 292 return FALSE; |
| 293 } | 293 } |
| 294 if (!m_pDocument) { | 294 if (!m_pDocument) { |
| 295 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 295 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 296 return FALSE; | 296 return FALSE; |
| 297 } | 297 } |
| 298 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 298 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 299 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 299 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 300 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 300 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 301 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 301 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 302 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 302 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 303 if (pPDFForm->CountFields(wideName) <= 0) { | 303 if (pPDFForm->CountFields(wideName) <= 0) { |
| 304 vRet.SetNull(pRuntime); | 304 vRet.SetNull(pRuntime); |
| 305 return TRUE; | 305 return TRUE; |
| 306 } | 306 } |
| 307 | 307 |
| 308 v8::Local<v8::Object> pFieldObj = | 308 v8::Local<v8::Object> pFieldObj = |
| 309 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); | 309 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
| 310 CJS_Field* pJSField = | 310 CJS_Field* pJSField = |
| 311 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); | 311 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 329 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 329 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 330 return FALSE; | 330 return FALSE; |
| 331 } | 331 } |
| 332 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 332 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 333 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 333 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 334 int nIndex = params[0].ToInt(pRuntime); | 334 int nIndex = params[0].ToInt(pRuntime); |
| 335 if (nIndex < 0) { | 335 if (nIndex < 0) { |
| 336 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 336 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 337 return FALSE; | 337 return FALSE; |
| 338 } | 338 } |
| 339 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 339 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 340 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 340 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 341 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); | 341 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); |
| 342 if (!pField) | 342 if (!pField) |
| 343 return FALSE; | 343 return FALSE; |
| 344 | 344 |
| 345 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); | 345 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
| 346 return TRUE; | 346 return TRUE; |
| 347 } | 347 } |
| 348 | 348 |
| 349 FX_BOOL Document::importAnFDF(IJS_Context* cc, | 349 FX_BOOL Document::importAnFDF(IJS_Context* cc, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 int iLength = params.size(); | 396 int iLength = params.size(); |
| 397 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; | 397 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; |
| 398 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; | 398 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 399 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; | 399 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 400 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; | 400 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
| 401 CFX_WideString cSubject = | 401 CFX_WideString cSubject = |
| 402 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; | 402 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 403 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; | 403 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
| 404 | 404 |
| 405 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 405 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 406 CFX_ByteTextBuf textBuf; | 406 CFX_ByteTextBuf textBuf; |
| 407 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | 407 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 408 return FALSE; | 408 return FALSE; |
| 409 | 409 |
| 410 pRuntime->BeginBlock(); | 410 pRuntime->BeginBlock(); |
| 411 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetReaderEnv(); | 411 CPDFSDK_FormFillEnvironment* pEnv = pContext->GetReaderEnv(); |
| 412 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | 412 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 413 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), | 413 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 414 cMsg.c_str()); | 414 cMsg.c_str()); |
| 415 pRuntime->EndBlock(); | 415 pRuntime->EndBlock(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 return FALSE; | 502 return FALSE; |
| 503 } | 503 } |
| 504 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 504 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 505 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { | 505 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
| 506 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 506 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 507 return FALSE; | 507 return FALSE; |
| 508 } | 508 } |
| 509 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 509 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 510 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 510 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 511 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); | 511 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
| 512 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 512 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 513 std::vector<CPDFSDK_Widget*> widgets; | 513 std::vector<CPDFSDK_Widget*> widgets; |
| 514 pInterForm->GetWidgets(sFieldName, &widgets); | 514 pInterForm->GetWidgets(sFieldName, &widgets); |
| 515 if (widgets.empty()) | 515 if (widgets.empty()) |
| 516 return TRUE; | 516 return TRUE; |
| 517 | 517 |
| 518 for (CPDFSDK_Widget* pWidget : widgets) { | 518 for (CPDFSDK_Widget* pWidget : widgets) { |
| 519 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 519 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
| 520 --rcAnnot.left; | 520 --rcAnnot.left; |
| 521 --rcAnnot.bottom; | 521 --rcAnnot.bottom; |
| 522 ++rcAnnot.right; | 522 ++rcAnnot.right; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 554 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 555 return FALSE; | 555 return FALSE; |
| 556 } | 556 } |
| 557 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 557 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 558 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 558 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 559 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { | 559 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 560 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 560 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 561 return FALSE; | 561 return FALSE; |
| 562 } | 562 } |
| 563 | 563 |
| 564 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 564 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 565 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 565 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 566 CJS_Array aName; | 566 CJS_Array aName; |
| 567 | 567 |
| 568 if (params.empty()) { | 568 if (params.empty()) { |
| 569 pPDFForm->ResetForm(TRUE); | 569 pPDFForm->ResetForm(TRUE); |
| 570 m_pDocument->SetChangeMark(); | 570 m_pDocument->SetChangeMark(); |
| 571 return TRUE; | 571 return TRUE; |
| 572 } | 572 } |
| 573 | 573 |
| 574 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 574 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); | 652 pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); |
| 653 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); | 653 bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 654 | 654 |
| 655 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); | 655 pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); |
| 656 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); | 656 bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); |
| 657 | 657 |
| 658 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); | 658 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); |
| 659 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); | 659 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); |
| 660 } | 660 } |
| 661 | 661 |
| 662 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 662 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 663 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 663 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 664 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { | 664 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { |
| 665 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | 665 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 666 pRuntime->BeginBlock(); | 666 pRuntime->BeginBlock(); |
| 667 pInterForm->SubmitForm(strURL, FALSE); | 667 pInterForm->SubmitForm(strURL, FALSE); |
| 668 pRuntime->EndBlock(); | 668 pRuntime->EndBlock(); |
| 669 } | 669 } |
| 670 return TRUE; | 670 return TRUE; |
| 671 } | 671 } |
| 672 | 672 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 return TRUE; | 1002 return TRUE; |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 FX_BOOL Document::calculate(IJS_Context* cc, | 1005 FX_BOOL Document::calculate(IJS_Context* cc, |
| 1006 CJS_PropValue& vp, | 1006 CJS_PropValue& vp, |
| 1007 CFX_WideString& sError) { | 1007 CFX_WideString& sError) { |
| 1008 if (!m_pDocument) { | 1008 if (!m_pDocument) { |
| 1009 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1009 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1010 return FALSE; | 1010 return FALSE; |
| 1011 } | 1011 } |
| 1012 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 1012 CPDFSDK_InterForm* pInterForm = m_pDocument->GetEnv()->GetInterForm(); |
| 1013 if (vp.IsGetting()) { | 1013 if (vp.IsGetting()) { |
| 1014 vp << !!pInterForm->IsCalculateEnabled(); | 1014 vp << !!pInterForm->IsCalculateEnabled(); |
| 1015 } else { | 1015 } else { |
| 1016 bool bCalculate; | 1016 bool bCalculate; |
| 1017 vp >> bCalculate; | 1017 vp >> bCalculate; |
| 1018 pInterForm->EnableCalculate(bCalculate); | 1018 pInterForm->EnableCalculate(bCalculate); |
| 1019 } | 1019 } |
| 1020 return TRUE; | 1020 return TRUE; |
| 1021 } | 1021 } |
| 1022 | 1022 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 if (!m_pDocument) { | 1380 if (!m_pDocument) { |
| 1381 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1381 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1382 return FALSE; | 1382 return FALSE; |
| 1383 } | 1383 } |
| 1384 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 1384 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 1385 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 1385 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1386 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { | 1386 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 1387 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1387 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1388 return FALSE; | 1388 return FALSE; |
| 1389 } | 1389 } |
| 1390 m_pDocument->GetInterForm()->OnCalculate(); | 1390 m_pDocument->GetEnv()->GetInterForm()->OnCalculate(); |
| 1391 return TRUE; | 1391 return TRUE; |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 FX_BOOL Document::Collab(IJS_Context* cc, | 1394 FX_BOOL Document::Collab(IJS_Context* cc, |
| 1395 CJS_PropValue& vp, | 1395 CJS_PropValue& vp, |
| 1396 CFX_WideString& sError) { | 1396 CFX_WideString& sError) { |
| 1397 return TRUE; | 1397 return TRUE; |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 FX_BOOL Document::getPageNthWord(IJS_Context* cc, | 1400 FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 } | 1721 } |
| 1722 } | 1722 } |
| 1723 | 1723 |
| 1724 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1724 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1725 Field::DoDelay(m_pDocument.Get(), pData.get()); | 1725 Field::DoDelay(m_pDocument.Get(), pData.get()); |
| 1726 } | 1726 } |
| 1727 | 1727 |
| 1728 CJS_Document* Document::GetCJSDoc() const { | 1728 CJS_Document* Document::GetCJSDoc() const { |
| 1729 return static_cast<CJS_Document*>(m_pJSObject); | 1729 return static_cast<CJS_Document*>(m_pJSObject); |
| 1730 } | 1730 } |
| OLD | NEW |