Resolve an old TODO() about non-v8 build using |JS_| functions.
Remove the JS_ prefix in the SubmitForm() case, as it is not
directly called from fxjs. Remove the JS_ prefix in the
GetFilePath() case, but also provide a JS_ wrapper. Ideally,
all of the JS_ functions would be declared as an interface
in fxjs itself, so this helps keep that consistent.
-- Make SubmitForm() take a span.
Change-Id: I79c3472fa7338112fede7965f5dfa014dad781df
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58970
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 49d83c0..4f46db4 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -216,9 +216,13 @@
}
m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
}
-#endif // PDF_ENABLE_V8
WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() {
+ return GetFilePath();
+}
+#endif // PDF_ENABLE_V8
+
+WideString CPDFSDK_FormFillEnvironment::GetFilePath() const {
if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
!m_pInfo->m_pJsPlatform->Doc_getFilePath) {
return WideString();
@@ -238,16 +242,16 @@
return WideString::FromDefANSI(ByteStringView(pBuff));
}
-void CPDFSDK_FormFillEnvironment::JS_docSubmitForm(void* formData,
- int length,
- const WideString& URL) {
+void CPDFSDK_FormFillEnvironment::SubmitForm(pdfium::span<uint8_t> form_data,
+ const WideString& URL) {
if (!m_pInfo || !m_pInfo->m_pJsPlatform ||
!m_pInfo->m_pJsPlatform->Doc_submitForm) {
return;
}
ByteString bsUrl = URL.ToUTF16LE();
- m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData,
- length, AsFPDFWideString(&bsUrl));
+ m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform,
+ form_data.data(), form_data.size(),
+ AsFPDFWideString(&bsUrl));
}
IJS_Runtime* CPDFSDK_FormFillEnvironment::GetIJSRuntime() {
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index 9453cd2..e815cf5 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -197,18 +197,17 @@
FPDF_BOOL bReverse,
FPDF_BOOL bAnnotations);
void JS_docgotoPage(int nPageNum);
+ WideString JS_docGetFilePath();
#endif // PDF_ENABLE_V8
bool IsJSPlatformPresent() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
- // TODO(tsepez): required even if !V8, investigate.
- WideString JS_docGetFilePath();
- void JS_docSubmitForm(void* formData, int length, const WideString& URL);
-
+ WideString GetFilePath() const;
ByteString GetAppName() const { return ByteString(); }
TimerHandlerIface* GetTimerHandler() { return this; }
IPWL_SystemHandler* GetSysHandler() { return this; }
FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
+ void SubmitForm(pdfium::span<uint8_t> form_data, const WideString& URL);
// Creates if not present.
CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index b33bd06..e75e58b 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -485,7 +485,7 @@
if (bUrlEncoded && !FDFToURLEncodedData(&buffer))
return false;
- m_pFormFillEnv->JS_docSubmitForm(buffer.data(), buffer.size(), csDestination);
+ m_pFormFillEnv->SubmitForm(buffer, csDestination);
return true;
}
@@ -493,7 +493,7 @@
const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude) {
std::unique_ptr<CFDF_Document> pFDF = m_pInteractiveForm->ExportToFDF(
- m_pFormFillEnv->JS_docGetFilePath(), fields, bIncludeOrExclude, false);
+ m_pFormFillEnv->GetFilePath(), fields, bIncludeOrExclude, false);
return pFDF ? pFDF->WriteToString() : ByteString();
}
@@ -503,8 +503,8 @@
if (sDestination.IsEmpty())
return false;
- std::unique_ptr<CFDF_Document> pFDFDoc = m_pInteractiveForm->ExportToFDF(
- m_pFormFillEnv->JS_docGetFilePath(), false);
+ std::unique_ptr<CFDF_Document> pFDFDoc =
+ m_pInteractiveForm->ExportToFDF(m_pFormFillEnv->GetFilePath(), false);
if (!pFDFDoc)
return false;
@@ -516,13 +516,13 @@
if (bUrlEncoded && !FDFToURLEncodedData(&buffer))
return false;
- m_pFormFillEnv->JS_docSubmitForm(buffer.data(), buffer.size(), sDestination);
+ m_pFormFillEnv->SubmitForm(buffer, sDestination);
return true;
}
ByteString CPDFSDK_InteractiveForm::ExportFormToFDFTextBuf() {
- std::unique_ptr<CFDF_Document> pFDF = m_pInteractiveForm->ExportToFDF(
- m_pFormFillEnv->JS_docGetFilePath(), false);
+ std::unique_ptr<CFDF_Document> pFDF =
+ m_pInteractiveForm->ExportToFDF(m_pFormFillEnv->GetFilePath(), false);
return pFDF ? pFDF->WriteToString() : ByteString();
}