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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 CJS_Value& vRet, | 512 CJS_Value& vRet, |
513 CFX_WideString& sError) { | 513 CFX_WideString& sError) { |
514 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 514 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
515 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | 515 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
516 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | 516 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
517 return FALSE; | 517 return FALSE; |
518 | 518 |
519 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 519 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
520 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 520 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
521 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 521 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
522 CJS_Array aName(pRuntime); | 522 CJS_Array aName; |
523 | 523 |
524 if (params.empty()) { | 524 if (params.empty()) { |
525 pPDFForm->ResetForm(TRUE); | 525 pPDFForm->ResetForm(TRUE); |
526 m_pDocument->SetChangeMark(); | 526 m_pDocument->SetChangeMark(); |
527 return TRUE; | 527 return TRUE; |
528 } | 528 } |
529 | 529 |
530 switch (params[0].GetType()) { | 530 switch (params[0].GetType()) { |
531 default: | 531 default: |
532 aName.Attach(params[0].ToV8Array()); | 532 aName.Attach(params[0].ToV8Array()); |
533 break; | 533 break; |
534 case CJS_Value::VT_string: | 534 case CJS_Value::VT_string: |
535 aName.SetElement(0, params[0]); | 535 aName.SetElement(pRuntime->GetIsolate(), 0, params[0]); |
536 break; | 536 break; |
537 } | 537 } |
538 | 538 |
539 std::vector<CPDF_FormField*> aFields; | 539 std::vector<CPDF_FormField*> aFields; |
540 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { | 540 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { |
541 CJS_Value valElement(pRuntime); | 541 CJS_Value valElement(pRuntime); |
542 aName.GetElement(i, valElement); | 542 aName.GetElement(pRuntime->GetIsolate(), i, valElement); |
543 CFX_WideString swVal = valElement.ToCFXWideString(); | 543 CFX_WideString swVal = valElement.ToCFXWideString(); |
544 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) | 544 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
545 aFields.push_back(pPDFForm->GetField(j, swVal)); | 545 aFields.push_back(pPDFForm->GetField(j, swVal)); |
546 } | 546 } |
547 | 547 |
548 if (!aFields.empty()) { | 548 if (!aFields.empty()) { |
549 pPDFForm->ResetForm(aFields, TRUE, TRUE); | 549 pPDFForm->ResetForm(aFields, TRUE, TRUE); |
550 m_pDocument->SetChangeMark(); | 550 m_pDocument->SetChangeMark(); |
551 } | 551 } |
552 | 552 |
(...skipping 14 matching lines...) Expand all Loading... |
567 CFX_WideString& sError) { | 567 CFX_WideString& sError) { |
568 CJS_Context* pContext = (CJS_Context*)cc; | 568 CJS_Context* pContext = (CJS_Context*)cc; |
569 int nSize = params.size(); | 569 int nSize = params.size(); |
570 if (nSize < 1) { | 570 if (nSize < 1) { |
571 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 571 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
572 return FALSE; | 572 return FALSE; |
573 } | 573 } |
574 | 574 |
575 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 575 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
576 v8::Isolate* isolate = pRuntime->GetIsolate(); | 576 v8::Isolate* isolate = pRuntime->GetIsolate(); |
577 CJS_Array aFields(pRuntime); | 577 CJS_Array aFields; |
578 CFX_WideString strURL; | 578 CFX_WideString strURL; |
579 FX_BOOL bFDF = TRUE; | 579 FX_BOOL bFDF = TRUE; |
580 FX_BOOL bEmpty = FALSE; | 580 FX_BOOL bEmpty = FALSE; |
581 | 581 |
582 CJS_Value v = params[0]; | 582 CJS_Value v = params[0]; |
583 if (v.GetType() == CJS_Value::VT_string) { | 583 if (v.GetType() == CJS_Value::VT_string) { |
584 strURL = params[0].ToCFXWideString(); | 584 strURL = params[0].ToCFXWideString(); |
585 if (nSize > 1) | 585 if (nSize > 1) |
586 bFDF = params[1].ToBool(); | 586 bFDF = params[1].ToBool(); |
587 if (nSize > 2) | 587 if (nSize > 2) |
(...skipping 23 matching lines...) Expand all Loading... |
611 pRuntime->BeginBlock(); | 611 pRuntime->BeginBlock(); |
612 pInterForm->SubmitForm(strURL, FALSE); | 612 pInterForm->SubmitForm(strURL, FALSE); |
613 pRuntime->EndBlock(); | 613 pRuntime->EndBlock(); |
614 } | 614 } |
615 return TRUE; | 615 return TRUE; |
616 } | 616 } |
617 | 617 |
618 std::vector<CPDF_FormField*> fieldObjects; | 618 std::vector<CPDF_FormField*> fieldObjects; |
619 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { | 619 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { |
620 CJS_Value valName(pRuntime); | 620 CJS_Value valName(pRuntime); |
621 aFields.GetElement(i, valName); | 621 aFields.GetElement(pRuntime->GetIsolate(), i, valName); |
622 | 622 |
623 CFX_WideString sName = valName.ToCFXWideString(); | 623 CFX_WideString sName = valName.ToCFXWideString(); |
624 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 624 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
625 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { | 625 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
626 CPDF_FormField* pField = pPDFForm->GetField(j, sName); | 626 CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
627 if (!bEmpty && pField->GetValue().IsEmpty()) | 627 if (!bEmpty && pField->GetValue().IsEmpty()) |
628 continue; | 628 continue; |
629 | 629 |
630 fieldObjects.push_back(pField); | 630 fieldObjects.push_back(pField); |
631 } | 631 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | 1092 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
1093 return FALSE; | 1093 return FALSE; |
1094 } | 1094 } |
1095 | 1095 |
1096 if (m_IconList.empty()) { | 1096 if (m_IconList.empty()) { |
1097 vp.SetNull(); | 1097 vp.SetNull(); |
1098 return TRUE; | 1098 return TRUE; |
1099 } | 1099 } |
1100 | 1100 |
1101 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1101 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1102 CJS_Array Icons(pRuntime); | 1102 CJS_Array Icons; |
1103 | 1103 |
1104 int i = 0; | 1104 int i = 0; |
1105 for (const auto& pIconElement : m_IconList) { | 1105 for (const auto& pIconElement : m_IconList) { |
1106 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 1106 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
1107 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | 1107 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
1108 if (pObj.IsEmpty()) | 1108 if (pObj.IsEmpty()) |
1109 return FALSE; | 1109 return FALSE; |
1110 | 1110 |
1111 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | 1111 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
1112 if (!pJS_Icon) | 1112 if (!pJS_Icon) |
1113 return FALSE; | 1113 return FALSE; |
1114 | 1114 |
1115 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1115 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
1116 if (!pIcon) | 1116 if (!pIcon) |
1117 return FALSE; | 1117 return FALSE; |
1118 | 1118 |
1119 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1119 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
1120 pIcon->SetIconName(pIconElement->IconName); | 1120 pIcon->SetIconName(pIconElement->IconName); |
1121 Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon)); | 1121 Icons.SetElement(pRuntime->GetIsolate(), i++, |
| 1122 CJS_Value(pRuntime, pJS_Icon)); |
1122 } | 1123 } |
1123 | 1124 |
1124 vp << Icons; | 1125 vp << Icons; |
1125 return TRUE; | 1126 return TRUE; |
1126 } | 1127 } |
1127 | 1128 |
1128 FX_BOOL Document::getIcon(IJS_Context* cc, | 1129 FX_BOOL Document::getIcon(IJS_Context* cc, |
1129 const std::vector<CJS_Value>& params, | 1130 const std::vector<CJS_Value>& params, |
1130 CJS_Value& vRet, | 1131 CJS_Value& vRet, |
1131 CFX_WideString& sError) { | 1132 CFX_WideString& sError) { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 } | 1470 } |
1470 } | 1471 } |
1471 | 1472 |
1472 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1473 for (const auto& pData : DelayDataForFieldAndControlIndex) |
1473 Field::DoDelay(m_pDocument, pData.get()); | 1474 Field::DoDelay(m_pDocument, pData.get()); |
1474 } | 1475 } |
1475 | 1476 |
1476 CJS_Document* Document::GetCJSDoc() const { | 1477 CJS_Document* Document::GetCJSDoc() const { |
1477 return static_cast<CJS_Document*>(m_pJSObject); | 1478 return static_cast<CJS_Document*>(m_pJSObject); |
1478 } | 1479 } |
OLD | NEW |