From 0784c7317e3aaa2c65d098cf2593b6b49986307d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Apr 2018 18:02:57 +0000 Subject: 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 Commit-Queue: Tom Sepez --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'fpdfsdk/fpdfxfa/cpdfxfa_context.cpp') 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(m_pFormFillEnv->GetIJSRuntime()); + return m_pFormFillEnv->GetIJSRuntime()->AsCJSRuntime(); } WideString CPDFXFA_Context::GetAppTitle() const { -- cgit v1.2.3