summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-23 18:02:57 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-23 18:02:57 +0000
commit0784c7317e3aaa2c65d098cf2593b6b49986307d (patch)
treea264d06dcd9fd0d914324d5bd0a96430cc543b87 /fpdfsdk
parent9f71afb882a9d1294f8a4392b8553e2c285f51c7 (diff)
downloadpdfium-0784c7317e3aaa2c65d098cf2593b6b49986307d.tar.xz
Disable JavaScript entirely if no JSPlatform passed by embedder.
Allows run-time selection of whether to permit JS inside PDF. Previously, this was a link-time decision only. This requires a little more caution before we decide that we have the CJS_Runtime, and not the CJS_RuntimeStub in a few casts. Adds a kDisableJavaScript option to the form fill embeddertests. Adds a --disable-javascript flag to the pdfium_test executable. Also adds a --disable-xfa flag while we're at it. Change-Id: I8d8ac95f6474459cadba9a60572fbb342e984646 Reviewed-on: https://pdfium-review.googlesource.com/31090 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp2
-rw-r--r--fpdfsdk/fpdf_formfill_embeddertest.cpp30
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp15
3 files changed, 39 insertions, 8 deletions
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index b3375d4501..272e27032b 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -203,8 +203,6 @@ void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) {
}
IJS_Runtime* CPDFSDK_FormFillEnvironment::GetIJSRuntime() {
- if (!IsJSPlatformPresent())
- return nullptr;
if (!m_pIJSRuntime)
m_pIJSRuntime = IJS_Runtime::Create(this);
return m_pIJSRuntime.get();
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 09e0c200d3..cedb96c0ca 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -380,6 +380,36 @@ TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
}
#ifdef PDF_ENABLE_V8
+TEST_F(FPDFFormFillEmbeddertest, DisableJavaScript) {
+ // Test that timers and intervals can't fire without JS.
+ EmbedderTestTimerHandlingDelegate delegate;
+ SetDelegate(&delegate);
+
+ EXPECT_TRUE(OpenDocumentWithoutJavaScript("bug_551248.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_TRUE(page);
+ DoOpenActions();
+
+ const auto& alerts = delegate.GetAlerts();
+ EXPECT_EQ(0U, alerts.size());
+
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ delegate.AdvanceTime(1000);
+ EXPECT_EQ(0U, alerts.size()); // nothing fired.
+ UnloadPage(page);
+}
+
TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
// Test that timers fire once and intervals fire repeatedly.
EmbedderTestTimerHandlingDelegate delegate;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index c85c1bd27e..7d1b28be70 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -81,11 +81,11 @@ void CPDFXFA_Context::SetFormFillEnv(
bool CPDFXFA_Context::LoadXFADoc() {
m_nLoadStatus = FXFA_LOADSTATUS_LOADING;
+ m_XFAPageList.clear();
+
if (!m_pPDFDoc)
return false;
- m_XFAPageList.clear();
-
CXFA_FFApp* pApp = GetXFAApp();
if (!pApp)
return false;
@@ -96,8 +96,13 @@ bool CPDFXFA_Context::LoadXFADoc() {
return false;
}
- m_pXFADoc->GetXFADoc()->InitScriptContext(GetCJSRuntime());
+ CJS_Runtime* actual_runtime = GetCJSRuntime(); // Null if a stub.
+ if (!actual_runtime) {
+ SetLastError(FPDF_ERR_XFALOAD);
+ return false;
+ }
+ m_pXFADoc->GetXFADoc()->InitScriptContext(actual_runtime);
if (m_pXFADoc->GetFormType() == FormType::kXFAFull)
m_FormType = FormType::kXFAFull;
else
@@ -113,7 +118,6 @@ bool CPDFXFA_Context::LoadXFADoc() {
m_pXFADocView->DoLayout();
m_pXFADocView->StopLayout();
m_nLoadStatus = FXFA_LOADSTATUS_LOADED;
-
return true;
}
@@ -196,8 +200,7 @@ CJS_Runtime* CPDFXFA_Context::GetCJSRuntime() const {
if (!m_pFormFillEnv)
return nullptr;
- // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub.
- return static_cast<CJS_Runtime*>(m_pFormFillEnv->GetIJSRuntime());
+ return m_pFormFillEnv->GetIJSRuntime()->AsCJSRuntime();
}
WideString CPDFXFA_Context::GetAppTitle() const {