• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 kScriptPropertyData[] = {
15     {XFA_Element::Exclude, 1, 0},
16     {XFA_Element::CurrentPage, 1, 0},
17     {XFA_Element::RunScripts, 1, 0},
18 };
19 
20 const CXFA_Node::AttributeData kScriptAttributeData[] = {
21     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
22     {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
23     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
24     {XFA_Attribute::ContentType, XFA_AttributeType::CData, nullptr},
25     {XFA_Attribute::RunAt, XFA_AttributeType::Enum,
26      (void*)XFA_AttributeValue::Client},
27     {XFA_Attribute::Binding, XFA_AttributeType::CData, nullptr},
28     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
29     {XFA_Attribute::Desc, XFA_AttributeType::CData, nullptr},
30     {XFA_Attribute::Lock, XFA_AttributeType::Integer, (void*)0},
31 };
32 
33 }  // namespace
34 
CXFA_Script(CXFA_Document * doc,XFA_PacketType packet)35 CXFA_Script::CXFA_Script(CXFA_Document* doc, XFA_PacketType packet)
36     : CXFA_Node(
37           doc,
38           packet,
39           (XFA_XDPPACKET_Config | XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
40           XFA_ObjectType::ContentNode,
41           XFA_Element::Script,
42           kScriptPropertyData,
43           kScriptAttributeData,
44           pdfium::MakeUnique<CJX_Script>(this)) {}
45 
46 CXFA_Script::~CXFA_Script() = default;
47 
GetContentType()48 CXFA_Script::Type CXFA_Script::GetContentType() {
49   Optional<WideString> cData =
50       JSObject()->TryCData(XFA_Attribute::ContentType, false);
51   if (!cData.has_value())
52     return Type::Formcalc;
53   if (cData.value().EqualsASCII("application/x-formcalc"))
54     return Type::Formcalc;
55   if (cData.value().EqualsASCII("application/x-javascript"))
56     return Type::Javascript;
57   return Type::Unknown;
58 }
59 
GetRunAt()60 XFA_AttributeValue 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