diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-09 20:44:55 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-09 20:44:55 +0000 |
commit | ab226471570afef1e3619e6480d5485f0a75fddd (patch) | |
tree | b2fbde8b4a52e7b3855e684fb537cb32a559a2c5 /fxjs/cjs_document.cpp | |
parent | 3e838a75ae5c0bb0e524f745df69e54a021fc5ec (diff) | |
download | pdfium-ab226471570afef1e3619e6480d5485f0a75fddd.tar.xz |
Add some helper methods to get InterForm objects in CJS_Document.
Add GetCoreInterForm() and GetSDKInterForm(), because otherwise there
are too many GetInterForm() calls.
Change-Id: Ibf910a51e477787c2b04b28bb359933b55dac34b
Reviewed-on: https://pdfium-review.googlesource.com/c/43597
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjs_document.cpp')
-rw-r--r-- | fxjs/cjs_document.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index 4d74768b1b..ddaa33e38a 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -208,8 +208,7 @@ CJS_Result CJS_Document::get_num_fields(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) return CJS_Result::Failure(JSMessage::kBadObjectError); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + CPDF_InterForm* pPDFForm = GetCoreInterForm(); return CJS_Result::Success(pRuntime->NewNumber( static_cast<int>(pPDFForm->CountFields(WideString())))); } @@ -319,8 +318,7 @@ CJS_Result CJS_Document::getField( return CJS_Result::Failure(JSMessage::kBadObjectError); WideString wideName = pRuntime->ToWideString(params[0]); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + CPDF_InterForm* pPDFForm = GetCoreInterForm(); if (pPDFForm->CountFields(wideName) <= 0) return CJS_Result::Success(pRuntime->NewUndefined()); @@ -351,8 +349,7 @@ CJS_Result CJS_Document::getNthFieldName( if (nIndex < 0) return CJS_Result::Failure(JSMessage::kValueError); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + CPDF_InterForm* pPDFForm = GetCoreInterForm(); CPDF_FormField* pField = pPDFForm->GetField(nIndex, WideString()); if (!pField) return CJS_Result::Failure(JSMessage::kBadObjectError); @@ -392,7 +389,7 @@ CJS_Result CJS_Document::mailForm( if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return CJS_Result::Failure(JSMessage::kPermissionError); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + CPDFSDK_InterForm* pInterForm = GetSDKInterForm(); ByteString sTextBuf = pInterForm->ExportFormToFDFTextBuf(); if (sTextBuf.GetLength() == 0) return CJS_Result::Failure(L"Bad FDF format."); @@ -488,7 +485,7 @@ CJS_Result CJS_Document::removeField( return CJS_Result::Failure(JSMessage::kPermissionError); WideString sFieldName = pRuntime->ToWideString(params[0]); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + CPDFSDK_InterForm* pInterForm = GetSDKInterForm(); std::vector<CPDFSDK_Annot::ObservedPtr> widgets; pInterForm->GetWidgets(sFieldName, &widgets); if (widgets.empty()) @@ -535,8 +532,7 @@ CJS_Result CJS_Document::resetForm( return CJS_Result::Failure(JSMessage::kPermissionError); } - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + CPDF_InterForm* pPDFForm = GetCoreInterForm(); if (params.empty()) { pPDFForm->ResetForm(NotificationOption::kNotify); m_pFormFillEnv->SetChangeMark(); @@ -612,13 +608,11 @@ CJS_Result CJS_Document::submitForm( aFields = pRuntime->ToArray(pRuntime->GetObjectProperty(pObj, L"aFields")); } - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - + CPDF_InterForm* pPDFForm = GetCoreInterForm(); if (pRuntime->GetArrayLength(aFields) == 0 && bEmpty) { - if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { + if (pPDFForm->CheckRequiredFields(nullptr, true)) { pRuntime->BeginBlock(); - pInterForm->SubmitForm(strURL, false); + GetSDKInterForm()->SubmitForm(strURL, false); pRuntime->EndBlock(); } return CJS_Result::Success(); @@ -628,7 +622,6 @@ CJS_Result CJS_Document::submitForm( for (size_t i = 0; i < pRuntime->GetArrayLength(aFields); ++i) { WideString sName = pRuntime->ToWideString(pRuntime->GetArrayElement(aFields, i)); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { CPDF_FormField* pField = pPDFForm->GetField(j, sName); if (!bEmpty && pField->GetValue().IsEmpty()) @@ -638,9 +631,9 @@ CJS_Result CJS_Document::submitForm( } } - if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { + if (pPDFForm->CheckRequiredFields(&fieldObjects, true)) { pRuntime->BeginBlock(); - pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); + GetSDKInterForm()->SubmitFields(strURL, fieldObjects, true, !bFDF); pRuntime->EndBlock(); } return CJS_Result::Success(); @@ -976,7 +969,7 @@ CJS_Result CJS_Document::get_calculate(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) return CJS_Result::Failure(JSMessage::kBadObjectError); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + CPDFSDK_InterForm* pInterForm = GetSDKInterForm(); return CJS_Result::Success( pRuntime->NewBoolean(!!pInterForm->IsCalculateEnabled())); } @@ -986,7 +979,7 @@ CJS_Result CJS_Document::set_calculate(CJS_Runtime* pRuntime, if (!m_pFormFillEnv) return CJS_Result::Failure(JSMessage::kBadObjectError); - CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); + CPDFSDK_InterForm* pInterForm = GetSDKInterForm(); pInterForm->EnableCalculate(pRuntime->ToBoolean(vp)); return CJS_Result::Success(); } @@ -1268,7 +1261,7 @@ CJS_Result CJS_Document::calculateNow( return CJS_Result::Failure(JSMessage::kPermissionError); } - m_pFormFillEnv->GetInterForm()->OnCalculate(nullptr); + GetSDKInterForm()->OnCalculate(nullptr); return CJS_Result::Success(); } @@ -1484,3 +1477,11 @@ void CJS_Document::DoFieldDelay(const WideString& sFieldName, for (const auto& pData : delayed_data) CJS_Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); } + +CPDF_InterForm* CJS_Document::GetCoreInterForm() { + return GetSDKInterForm()->GetInterForm(); +} + +CPDFSDK_InterForm* CJS_Document::GetSDKInterForm() { + return m_pFormFillEnv->GetInterForm(); +} |