1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fxfa/parser/cxfa_script.h"
8
9 #include "fxjs/xfa/cjx_script.h"
10 #include "third_party/base/ptr_util.h"
11
12 namespace {
13
14 const CXFA_Node::PropertyData kPropertyData[] = {
15 {XFA_Element::Exclude, 1, 0},
16 {XFA_Element::CurrentPage, 1, 0},
17 {XFA_Element::RunScripts, 1, 0},
18 {XFA_Element::Unknown, 0, 0}};
19 const CXFA_Node::AttributeData kAttributeData[] = {
20 {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
21 {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
22 {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
23 {XFA_Attribute::ContentType, XFA_AttributeType::CData, nullptr},
24 {XFA_Attribute::RunAt, XFA_AttributeType::Enum,
25 (void*)XFA_AttributeEnum::Client},
26 {XFA_Attribute::Binding, XFA_AttributeType::CData, nullptr},
27 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
28 {XFA_Attribute::Desc, XFA_AttributeType::CData, nullptr},
29 {XFA_Attribute::Lock, XFA_AttributeType::Integer, (void*)0},
30 {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}};
31
32 constexpr wchar_t kName[] = L"script";
33
34 } // namespace
35
CXFA_Script(CXFA_Document * doc,XFA_PacketType packet)36 CXFA_Script::CXFA_Script(CXFA_Document* doc, XFA_PacketType packet)
37 : CXFA_Node(
38 doc,
39 packet,
40 (XFA_XDPPACKET_Config | XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
41 XFA_ObjectType::ContentNode,
42 XFA_Element::Script,
43 kPropertyData,
44 kAttributeData,
45 kName,
46 pdfium::MakeUnique<CJX_Script>(this)) {}
47
~CXFA_Script()48 CXFA_Script::~CXFA_Script() {}
49
GetContentType()50 CXFA_Script::Type CXFA_Script::GetContentType() {
51 Optional<WideString> cData =
52 JSObject()->TryCData(XFA_Attribute::ContentType, false);
53 if (!cData || *cData == L"application/x-formcalc")
54 return Type::Formcalc;
55 if (*cData == L"application/x-javascript")
56 return Type::Javascript;
57 return Type::Unknown;
58 }
59
GetRunAt()60 XFA_AttributeEnum CXFA_Script::GetRunAt() {
61 return JSObject()->GetEnum(XFA_Attribute::RunAt);
62 }
63
GetExpression()64 WideString CXFA_Script::GetExpression() {
65 return JSObject()->GetContent(false);
66 }
67