diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-14 20:29:23 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-14 20:29:23 +0000 |
commit | 07c0a4952a9fe45e51c6ba5a2e19296e52ea6ec7 (patch) | |
tree | 818bfc4ae4832250add9f92037994832f22b8e89 | |
parent | c5e0f66f5f2e0645f2beab70b44690fe510a9f2d (diff) | |
download | pdfium-07c0a4952a9fe45e51c6ba5a2e19296e52ea6ec7.tar.xz |
Fold CXFA_ScriptData into CXFA_Script
This CL removes the CXFA_ScriptData wrapper and uses CXFA_Script
directly.
Change-Id: I1f1932ef96ee4a24407de7eb1d68b8631a5a67ea
Reviewed-on: https://pdfium-review.googlesource.com/21173
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 16 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.h | 7 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.cpp | 6 | ||||
-rw-r--r-- | testing/xfa_js_embedder_test.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdocview.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fffield.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnotify.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnotify.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidgethandler.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 29 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.h | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_calculatedata.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_calculatedata.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_eventdata.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_eventdata.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 23 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_script.cpp | 18 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_script.h | 11 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptdata.cpp | 29 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptdata.h | 32 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validate.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validate.h | 4 |
23 files changed, 104 insertions, 131 deletions
@@ -2603,8 +2603,6 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_runscripts.h", "xfa/fxfa/parser/cxfa_script.cpp", "xfa/fxfa/parser/cxfa_script.h", - "xfa/fxfa/parser/cxfa_scriptdata.cpp", - "xfa/fxfa/parser/cxfa_scriptdata.h", "xfa/fxfa/parser/cxfa_scriptmodel.cpp", "xfa/fxfa/parser/cxfa_scriptmodel.h", "xfa/fxfa/parser/cxfa_select.cpp", diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index 65aedddf4f..a1c70a7d16 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -98,7 +98,7 @@ CFXJSE_Engine::CFXJSE_Engine(CXFA_Document* pDocument, v8::Isolate* pIsolate) &GlobalClassDescriptor, pDocument->GetRoot())), m_pJsClass(nullptr), - m_eScriptType(CXFA_ScriptData::Type::Unknown), + m_eScriptType(CXFA_Script::Type::Unknown), m_pScriptNodeArray(nullptr), m_ResolveProcessor(pdfium::MakeUnique<CFXJSE_ResolveProcessor>()), m_pThisObject(nullptr), @@ -117,14 +117,14 @@ CFXJSE_Engine::~CFXJSE_Engine() { delete ToThisProxy(pair.second->GetGlobalObject().get(), nullptr); } -bool CFXJSE_Engine::RunScript(CXFA_ScriptData::Type eScriptType, +bool CFXJSE_Engine::RunScript(CXFA_Script::Type eScriptType, const WideStringView& wsScript, CFXJSE_Value* hRetValue, CXFA_Object* pThisObject) { ByteString btScript; - AutoRestorer<CXFA_ScriptData::Type> typeRestorer(&m_eScriptType); + AutoRestorer<CXFA_Script::Type> typeRestorer(&m_eScriptType); m_eScriptType = eScriptType; - if (eScriptType == CXFA_ScriptData::Type::Formcalc) { + if (eScriptType == CXFA_Script::Type::Formcalc) { if (!m_FM2JSContext) { m_FM2JSContext = pdfium::MakeUnique<CFXJSE_FormCalcContext>( GetIsolate(), m_JsContext.get(), m_pDocument.Get()); @@ -210,7 +210,7 @@ void CFXJSE_Engine::GlobalPropertyGetter(CFXJSE_Value* pObject, CXFA_Document* pDoc = pOriginalObject->GetDocument(); CFXJSE_Engine* lpScriptContext = pDoc->GetScriptContext(); WideString wsPropName = WideString::FromUTF8(szPropName); - if (lpScriptContext->GetType() == CXFA_ScriptData::Type::Formcalc) { + if (lpScriptContext->GetType() == CXFA_Script::Type::Formcalc) { if (szPropName == kFormCalcRuntime) { lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); return; @@ -305,7 +305,7 @@ void CFXJSE_Engine::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, return; if (pObject == lpScriptContext->GetThisObject() || - (lpScriptContext->GetType() == CXFA_ScriptData::Type::Javascript && + (lpScriptContext->GetType() == CXFA_Script::Type::Javascript && !lpScriptContext->IsStrictScopeInJavaScript())) { bRet = lpScriptContext->QueryNodeByFlag( ToNode(pObject), wsPropName.AsStringView(), pReturnValue, @@ -417,7 +417,7 @@ bool CFXJSE_Engine::IsStrictScopeInJavaScript() { return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); } -CXFA_ScriptData::Type CFXJSE_Engine::GetType() { +CXFA_Script::Type CFXJSE_Engine::GetType() { return m_eScriptType; } @@ -537,7 +537,7 @@ bool CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, if (wsExpression.IsEmpty()) return false; - if (m_eScriptType != CXFA_ScriptData::Type::Formcalc || + if (m_eScriptType != CXFA_Script::Type::Formcalc || (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { m_upObjectArray.clear(); } diff --git a/fxjs/cfxjse_engine.h b/fxjs/cfxjse_engine.h index 9541f7b26b..777921dfc4 100644 --- a/fxjs/cfxjse_engine.h +++ b/fxjs/cfxjse_engine.h @@ -15,6 +15,7 @@ #include "fxjs/cjs_v8.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_script.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #define XFA_RESOLVENODE_TagName 0x0002 @@ -53,7 +54,7 @@ class CFXJSE_Engine : public CJS_V8 { void SetEventParam(CXFA_EventParam param) { m_eventParam = param; } CXFA_EventParam* GetEventParam() { return &m_eventParam; } - bool RunScript(CXFA_ScriptData::Type eScriptType, + bool RunScript(CXFA_Script::Type eScriptType, const WideStringView& wsScript, CFXJSE_Value* pRetValue, CXFA_Object* pThisObject); @@ -78,7 +79,7 @@ class CFXJSE_Engine : public CJS_V8 { void SetRunAtType(XFA_AttributeEnum eRunAt) { m_eRunAtType = eRunAt; } bool IsRunAtClient() { return m_eRunAtType != XFA_AttributeEnum::Server; } - CXFA_ScriptData::Type GetType(); + CXFA_Script::Type GetType(); std::vector<CXFA_Node*>* GetUpObjectArray() { return &m_upObjectArray; } CXFA_Document* GetDocument() const { return m_pDocument.Get(); } @@ -102,7 +103,7 @@ class CFXJSE_Engine : public CJS_V8 { UnownedPtr<CXFA_Document> const m_pDocument; std::unique_ptr<CFXJSE_Context> m_JsContext; CFXJSE_Class* m_pJsClass; - CXFA_ScriptData::Type m_eScriptType; + CXFA_Script::Type m_eScriptType; std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Value>> m_mapObjectToValue; std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Context>> m_mapVariableToContext; diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp index f3e4a21312..75c5eea6b5 100644 --- a/fxjs/cfxjse_resolveprocessor.cpp +++ b/fxjs/cfxjse_resolveprocessor.cpp @@ -624,11 +624,11 @@ void CFXJSE_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, CFXJSE_ResolveNodeData& rnd) { ASSERT(iFoundCount == pdfium::CollectionSize<int32_t>(rnd.m_Objects)); WideString wsExpression; - CXFA_ScriptData::Type eLangType = CXFA_ScriptData::Type::Unknown; + CXFA_Script::Type eLangType = CXFA_Script::Type::Unknown; if (wsCondition.Left(2) == L".[" && wsCondition.Last() == L']') - eLangType = CXFA_ScriptData::Type::Formcalc; + eLangType = CXFA_Script::Type::Formcalc; else if (wsCondition.Left(2) == L".(" && wsCondition.Last() == L')') - eLangType = CXFA_ScriptData::Type::Javascript; + eLangType = CXFA_Script::Type::Javascript; else return; diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp index 966264d735..db297292c6 100644 --- a/testing/xfa_js_embedder_test.cpp +++ b/testing/xfa_js_embedder_test.cpp @@ -74,7 +74,7 @@ bool XFAJSEmbedderTest::ExecuteSilenceFailure(const ByteStringView& input) { bool XFAJSEmbedderTest::ExecuteHelper(const ByteStringView& input) { value_ = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate()); - return script_context_->RunScript(CXFA_ScriptData::Type::Formcalc, + return script_context_->RunScript(CXFA_Script::Type::Formcalc, WideString::FromUTF8(input).AsStringView(), value_.get(), GetXFADocument()->GetRoot()); } diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 25a357bc46..30ae7124de 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -417,7 +417,7 @@ static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView, if (pWidgetAcc->GetNode()->IsUserInteractive()) return XFA_EVENTERROR_Disabled; - return pWidgetAcc->ExecuteScript(calcData.GetScriptData(), pParam); + return pWidgetAcc->ExecuteScript(calcData.GetScript(), pParam); } default: break; diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index e377fe1d2d..2b4748771e 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -23,6 +23,7 @@ #include "xfa/fxfa/cxfa_fwltheme.h" #include "xfa/fxfa/cxfa_textlayout.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_script.h" #include "xfa/fxgraphics/cxfa_gecolor.h" #include "xfa/fxgraphics/cxfa_gepath.h" @@ -680,10 +681,10 @@ int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { } case XFA_AttributeEnum::Warning: { if (version <= XFA_VERSION_204) { - CXFA_ScriptData scriptData = calcData.GetScriptData(); - if (!scriptData.HasValidNode()) + CXFA_Script* script = calcData.GetScript(); + if (!script) return 1; - if (scriptData.GetExpression().IsEmpty()) + if (script->GetExpression().IsEmpty()) return 1; } diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index ef0b971424..9da75bde23 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -202,7 +202,7 @@ bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos); } -bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { +bool CXFA_FFNotify::RunScript(CXFA_Script* pScript, CXFA_Node* pFormItem) { CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); if (!pDocView) return false; @@ -216,8 +216,7 @@ bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { int32_t iRet; bool bRet; - std::tie(iRet, bRet) = - pWidgetAcc->ExecuteBoolScript(CXFA_ScriptData(pScript), &EventParam); + std::tie(iRet, bRet) = pWidgetAcc->ExecuteBoolScript(pScript, &EventParam); return iRet == XFA_EVENTERROR_Success && bRet; } diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h index 248f633a3d..651e91f21b 100644 --- a/xfa/fxfa/cxfa_ffnotify.h +++ b/xfa/fxfa/cxfa_ffnotify.h @@ -49,7 +49,7 @@ class CXFA_FFNotify { bool FindSplitPos(CXFA_Node* pItem, int32_t iBlockIndex, float& fCalcHeightPos); - bool RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem); + bool RunScript(CXFA_Script* pScript, CXFA_Node* pFormItem); int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady = false, diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index 39919bc1e7..685e92d61a 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -191,11 +191,11 @@ bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, switch (eEventType) { case XFA_EVENT_Calculate: { CXFA_CalculateData calcData = pWidgetAcc->GetCalculateData(); - return calcData.HasValidNode() && calcData.GetScriptData().HasValidNode(); + return calcData.HasValidNode() && calcData.GetScript(); } case XFA_EVENT_Validate: { CXFA_Validate* validate = pWidgetAcc->GetValidate(false); - return validate && validate->GetScriptData().HasValidNode(); + return validate && validate->GetScript(); } default: break; @@ -226,9 +226,7 @@ int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, return XFA_EVENTERROR_NotExist; if (pWidgetAcc->GetNode()->IsUserInteractive()) return XFA_EVENTERROR_Disabled; - - CXFA_ScriptData script = calcData.GetScriptData(); - return pWidgetAcc->ExecuteScript(script, pParam); + return pWidgetAcc->ExecuteScript(calcData.GetScript(), pParam); } default: break; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 755821ef6b..29685b02e8 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -24,6 +24,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_script.h" #include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/cxfa_value.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -307,7 +308,7 @@ int32_t CXFA_WidgetAcc::ProcessEvent(const CXFA_EventData& eventData, case XFA_Element::Execute: break; case XFA_Element::Script: - return ExecuteScript(eventData.GetScriptData(), pEventParam); + return ExecuteScript(eventData.GetScript(), pEventParam); case XFA_Element::SignData: break; case XFA_Element::Submit: @@ -331,7 +332,7 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { CXFA_EventParam EventParam; EventParam.m_eType = XFA_EVENT_Calculate; - int32_t iRet = ExecuteScript(calcData.GetScriptData(), &EventParam); + int32_t iRet = ExecuteScript(calcData.GetScript(), &EventParam); if (iRet != XFA_EVENTERROR_Success) return iRet; @@ -539,14 +540,14 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; int32_t iFormat = 0; int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_ScriptData scriptData = validate->GetScriptData(); + CXFA_Script* script = validate->GetScript(); bool bRet = false; bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty(); - if (scriptData.HasValidNode()) { + if (script) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Validate; eParam.m_pTarget = this; - std::tie(iRet, bRet) = ExecuteBoolScript(scriptData, &eParam); + std::tie(iRet, bRet) = ExecuteBoolScript(script, &eParam); } XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); @@ -570,39 +571,39 @@ int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { return iRet | iFormat; } -int32_t CXFA_WidgetAcc::ExecuteScript(const CXFA_ScriptData& scriptData, +int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script* script, CXFA_EventParam* pEventParam) { bool bRet; int32_t iRet; - std::tie(iRet, bRet) = ExecuteBoolScript(scriptData, pEventParam); + std::tie(iRet, bRet) = ExecuteBoolScript(script, pEventParam); return iRet; } std::pair<int32_t, bool> CXFA_WidgetAcc::ExecuteBoolScript( - CXFA_ScriptData scriptData, + CXFA_Script* script, CXFA_EventParam* pEventParam) { static const uint32_t MAX_RECURSION_DEPTH = 2; if (m_nRecursionDepth > MAX_RECURSION_DEPTH) return {XFA_EVENTERROR_Success, false}; ASSERT(pEventParam); - if (!scriptData.HasValidNode()) + if (!script) return {XFA_EVENTERROR_NotExist, false}; - if (scriptData.GetRunAt() == XFA_AttributeEnum::Server) + if (script->GetRunAt() == XFA_AttributeEnum::Server) return {XFA_EVENTERROR_Disabled, false}; - WideString wsExpression = scriptData.GetExpression(); + WideString wsExpression = script->GetExpression(); if (wsExpression.IsEmpty()) return {XFA_EVENTERROR_NotExist, false}; - CXFA_ScriptData::Type eScriptType = scriptData.GetContentType(); - if (eScriptType == CXFA_ScriptData::Type::Unknown) + CXFA_Script::Type eScriptType = script->GetContentType(); + if (eScriptType == CXFA_Script::Type::Unknown) return {XFA_EVENTERROR_Success, false}; CXFA_FFDoc* pDoc = GetDoc(); CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext(); pContext->SetEventParam(*pEventParam); - pContext->SetRunAtType(scriptData.GetRunAt()); + pContext->SetRunAtType(script->GetRunAt()); std::vector<CXFA_Node*> refNodes; if (pEventParam->m_eType == XFA_EVENT_InitCalculate || diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index 4a46a9d80b..e193bd2069 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -18,7 +18,6 @@ #include "xfa/fxfa/parser/cxfa_eventdata.h" #include "xfa/fxfa/parser/cxfa_imagedata.h" #include "xfa/fxfa/parser/cxfa_margindata.h" -#include "xfa/fxfa/parser/cxfa_scriptdata.h" #include "xfa/fxfa/parser/cxfa_widgetdata.h" class CFGAS_GEFont; @@ -28,6 +27,7 @@ class CXFA_FFDoc; class CXFA_FFDocView; class CXFA_FFWidget; class CXFA_Node; +class CXFA_Script; class CXFA_TextLayout; class CXFA_WidgetLayoutData; class IXFA_AppProvider; @@ -49,9 +49,8 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { CXFA_EventParam* pEventParam); int32_t ProcessCalculate(); int32_t ProcessValidate(int32_t iFlags); - int32_t ExecuteScript(const CXFA_ScriptData& scriptData, - CXFA_EventParam* pEventParam); - std::pair<int32_t, bool> ExecuteBoolScript(CXFA_ScriptData scriptData, + int32_t ExecuteScript(CXFA_Script* script, CXFA_EventParam* pEventParam); + std::pair<int32_t, bool> ExecuteBoolScript(CXFA_Script* script, CXFA_EventParam* pEventParam); CXFA_FFWidget* GetNextWidget(CXFA_FFWidget* pWidget); diff --git a/xfa/fxfa/parser/cxfa_calculatedata.cpp b/xfa/fxfa/parser/cxfa_calculatedata.cpp index 32dc8ef5b7..3d7711d433 100644 --- a/xfa/fxfa/parser/cxfa_calculatedata.cpp +++ b/xfa/fxfa/parser/cxfa_calculatedata.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/cxfa_calculatedata.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_script.h" #include "xfa/fxfa/parser/cxfa_text.h" CXFA_CalculateData::CXFA_CalculateData(CXFA_Node* pNode) @@ -18,8 +19,9 @@ XFA_AttributeEnum CXFA_CalculateData::GetOverride() const { .value_or(XFA_AttributeEnum::Error); } -CXFA_ScriptData CXFA_CalculateData::GetScriptData() const { - return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); +CXFA_Script* CXFA_CalculateData::GetScript() const { + return static_cast<CXFA_Script*>( + m_pNode->GetChild(0, XFA_Element::Script, false)); } WideString CXFA_CalculateData::GetMessageText() const { diff --git a/xfa/fxfa/parser/cxfa_calculatedata.h b/xfa/fxfa/parser/cxfa_calculatedata.h index 833b1508a4..3e0802e6c4 100644 --- a/xfa/fxfa/parser/cxfa_calculatedata.h +++ b/xfa/fxfa/parser/cxfa_calculatedata.h @@ -9,16 +9,16 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/parser/cxfa_datadata.h" -#include "xfa/fxfa/parser/cxfa_scriptdata.h" class CXFA_Node; +class CXFA_Script; class CXFA_CalculateData : public CXFA_DataData { public: explicit CXFA_CalculateData(CXFA_Node* pNode); XFA_AttributeEnum GetOverride() const; - CXFA_ScriptData GetScriptData() const; + CXFA_Script* GetScript() const; WideString GetMessageText() const; }; diff --git a/xfa/fxfa/parser/cxfa_eventdata.cpp b/xfa/fxfa/parser/cxfa_eventdata.cpp index 062d881cda..d5b170b734 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.cpp +++ b/xfa/fxfa/parser/cxfa_eventdata.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/cxfa_eventdata.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_script.h" #include "xfa/fxfa/parser/cxfa_submit.h" CXFA_EventData::CXFA_EventData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} @@ -31,8 +32,9 @@ WideString CXFA_EventData::GetRef() const { return m_pNode->JSObject()->GetCData(XFA_Attribute::Ref); } -CXFA_ScriptData CXFA_EventData::GetScriptData() const { - return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); +CXFA_Script* CXFA_EventData::GetScript() const { + return static_cast<CXFA_Script*>( + m_pNode->GetChild(0, XFA_Element::Script, false)); } CXFA_Submit* CXFA_EventData::GetSubmit() const { diff --git a/xfa/fxfa/parser/cxfa_eventdata.h b/xfa/fxfa/parser/cxfa_eventdata.h index 63349690ab..8338767fe0 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.h +++ b/xfa/fxfa/parser/cxfa_eventdata.h @@ -11,9 +11,9 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/parser/cxfa_datadata.h" -#include "xfa/fxfa/parser/cxfa_scriptdata.h" class CXFA_Node; +class CXFA_Script; class CXFA_Submit; class CXFA_EventData : public CXFA_DataData { @@ -22,7 +22,7 @@ class CXFA_EventData : public CXFA_DataData { XFA_AttributeEnum GetActivity(); XFA_Element GetEventType() const; - CXFA_ScriptData GetScriptData() const; + CXFA_Script* GetScript() const; CXFA_Submit* GetSubmit() const; WideString GetRef() const; }; diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index f9040d6b4d..4d70d7d50f 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -229,6 +229,15 @@ void SyncRemoveLayoutItem(CXFA_LayoutItem* pParentLayoutItem, } } +bool RunBreakTestScript(CXFA_Script* pTestScript) { + WideString wsExpression = pTestScript->JSObject()->GetContent(false); + if (wsExpression.IsEmpty()) + return true; + return pTestScript->GetDocument()->GetNotify()->RunScript( + pTestScript, pTestScript->GetNodeItem(XFA_NODEITEM_Parent, + XFA_ObjectType::ContainerNode)); +} + } // namespace class CXFA_ContainerRecord { @@ -481,15 +490,6 @@ float CXFA_LayoutPageMgr::GetAvailHeight() { return FLT_MAX; } -bool XFA_LayoutPageMgr_RunBreakTestScript(CXFA_Node* pTestScript) { - WideString wsExpression = pTestScript->JSObject()->GetContent(false); - if (wsExpression.IsEmpty()) - return true; - return pTestScript->GetDocument()->GetNotify()->RunScript( - pTestScript, pTestScript->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode)); -} - CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( CXFA_Node* pPageNode, bool bCreateNew) { @@ -816,8 +816,9 @@ bool CXFA_LayoutPageMgr::ExecuteBreakBeforeOrAfter( CXFA_Node* pContainer = pFormNode->GetTemplateNode(); bool bStartNew = pCurNode->JSObject()->GetInteger(XFA_Attribute::StartNew) != 0; - CXFA_Node* pScript = pCurNode->GetFirstChildByClass(XFA_Element::Script); - if (pScript && !XFA_LayoutPageMgr_RunBreakTestScript(pScript)) + CXFA_Script* pScript = static_cast<CXFA_Script*>( + pCurNode->GetFirstChildByClass(XFA_Element::Script)); + if (pScript && !RunBreakTestScript(pScript)) return false; WideString wsTarget = diff --git a/xfa/fxfa/parser/cxfa_script.cpp b/xfa/fxfa/parser/cxfa_script.cpp index ab317f38e8..1b784b331b 100644 --- a/xfa/fxfa/parser/cxfa_script.cpp +++ b/xfa/fxfa/parser/cxfa_script.cpp @@ -46,3 +46,21 @@ CXFA_Script::CXFA_Script(CXFA_Document* doc, XFA_PacketType packet) pdfium::MakeUnique<CJX_Script>(this)) {} CXFA_Script::~CXFA_Script() {} + +CXFA_Script::Type CXFA_Script::GetContentType() { + pdfium::Optional<WideString> cData = + JSObject()->TryCData(XFA_Attribute::ContentType, false); + if (!cData || *cData == L"application/x-formcalc") + return Type::Formcalc; + if (*cData == L"application/x-javascript") + return Type::Javascript; + return Type::Unknown; +} + +XFA_AttributeEnum CXFA_Script::GetRunAt() { + return JSObject()->GetEnum(XFA_Attribute::RunAt); +} + +WideString CXFA_Script::GetExpression() { + return JSObject()->GetContent(false); +} diff --git a/xfa/fxfa/parser/cxfa_script.h b/xfa/fxfa/parser/cxfa_script.h index d14f7c113b..8ea7aac60b 100644 --- a/xfa/fxfa/parser/cxfa_script.h +++ b/xfa/fxfa/parser/cxfa_script.h @@ -7,12 +7,23 @@ #ifndef XFA_FXFA_PARSER_CXFA_SCRIPT_H_ #define XFA_FXFA_PARSER_CXFA_SCRIPT_H_ +#include "core/fxcrt/widestring.h" #include "xfa/fxfa/parser/cxfa_node.h" class CXFA_Script : public CXFA_Node { public: + enum class Type { + Formcalc = 0, + Javascript, + Unknown, + }; + CXFA_Script(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Script() override; + + Type GetContentType(); + XFA_AttributeEnum GetRunAt(); + WideString GetExpression(); }; #endif // XFA_FXFA_PARSER_CXFA_SCRIPT_H_ diff --git a/xfa/fxfa/parser/cxfa_scriptdata.cpp b/xfa/fxfa/parser/cxfa_scriptdata.cpp deleted file mode 100644 index 7e9f49066f..0000000000 --- a/xfa/fxfa/parser/cxfa_scriptdata.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_scriptdata.h" - -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_ScriptData::CXFA_ScriptData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} - -CXFA_ScriptData::Type CXFA_ScriptData::GetContentType() const { - pdfium::Optional<WideString> cData = - m_pNode->JSObject()->TryCData(XFA_Attribute::ContentType, false); - if (!cData || *cData == L"application/x-formcalc") - return Type::Formcalc; - if (*cData == L"application/x-javascript") - return Type::Javascript; - return Type::Unknown; -} - -XFA_AttributeEnum CXFA_ScriptData::GetRunAt() const { - return m_pNode->JSObject()->GetEnum(XFA_Attribute::RunAt); -} - -WideString CXFA_ScriptData::GetExpression() const { - return m_pNode->JSObject()->GetContent(false); -} diff --git a/xfa/fxfa/parser/cxfa_scriptdata.h b/xfa/fxfa/parser/cxfa_scriptdata.h deleted file mode 100644 index 983addbd0c..0000000000 --- a/xfa/fxfa/parser/cxfa_scriptdata.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ -#define XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ - -#include <stdint.h> - -#include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/parser/cxfa_datadata.h" - -class CXFA_Node; - -class CXFA_ScriptData : public CXFA_DataData { - public: - enum class Type { - Formcalc = 0, - Javascript, - Unknown, - }; - - explicit CXFA_ScriptData(CXFA_Node* pNode); - - Type GetContentType() const; - XFA_AttributeEnum GetRunAt() const; - WideString GetExpression() const; -}; - -#endif // XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_validate.cpp b/xfa/fxfa/parser/cxfa_validate.cpp index 9b31a17434..57cf5d4ecf 100644 --- a/xfa/fxfa/parser/cxfa_validate.cpp +++ b/xfa/fxfa/parser/cxfa_validate.cpp @@ -8,6 +8,7 @@ #include "fxjs/xfa/cjx_validate.h" #include "third_party/base/ptr_util.h" +#include "xfa/fxfa/parser/cxfa_script.h" namespace { @@ -144,6 +145,6 @@ WideString CXFA_Validate::GetPicture() { return pNode ? pNode->JSObject()->GetContent(false) : L""; } -CXFA_ScriptData CXFA_Validate::GetScriptData() { - return CXFA_ScriptData(GetChild(0, XFA_Element::Script, false)); +CXFA_Script* CXFA_Validate::GetScript() { + return static_cast<CXFA_Script*>(GetChild(0, XFA_Element::Script, false)); } diff --git a/xfa/fxfa/parser/cxfa_validate.h b/xfa/fxfa/parser/cxfa_validate.h index 9e2be9c959..df08ea6d3d 100644 --- a/xfa/fxfa/parser/cxfa_validate.h +++ b/xfa/fxfa/parser/cxfa_validate.h @@ -9,6 +9,8 @@ #include "xfa/fxfa/parser/cxfa_node.h" +class CXFA_Script; + class CXFA_Validate : public CXFA_Node { public: CXFA_Validate(CXFA_Document* doc, XFA_PacketType packet); @@ -29,7 +31,7 @@ class CXFA_Validate : public CXFA_Node { void SetScriptMessageText(const WideString& wsMessage); WideString GetPicture(); - CXFA_ScriptData GetScriptData(); + CXFA_Script* GetScript(); private: WideString GetMessageText(const WideString& wsMessageType); |