xref: /aosp_15_r20/external/pdfium/xfa/fxfa/parser/cxfa_exdata.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2017 The PDFium Authors
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_exdata.h"
8 
9 #include "fxjs/xfa/cjx_object.h"
10 #include "xfa/fxfa/parser/cxfa_document.h"
11 
12 namespace {
13 
14 const CXFA_Node::AttributeData kExDataAttributeData[] = {
15     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
16     {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
17     {XFA_Attribute::Rid, XFA_AttributeType::CData, nullptr},
18     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
19     {XFA_Attribute::ContentType, XFA_AttributeType::CData, nullptr},
20     {XFA_Attribute::TransferEncoding, XFA_AttributeType::Enum,
21      (void*)XFA_AttributeValue::None},
22     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
23     {XFA_Attribute::MaxLength, XFA_AttributeType::Integer, (void*)-1},
24     {XFA_Attribute::Href, XFA_AttributeType::CData, nullptr},
25 };
26 
27 }  // namespace
28 
29 // static
FromNode(CXFA_Node * pNode)30 CXFA_ExData* CXFA_ExData::FromNode(CXFA_Node* pNode) {
31   return pNode && pNode->GetElementType() == XFA_Element::ExData
32              ? static_cast<CXFA_ExData*>(pNode)
33              : nullptr;
34 }
35 
CXFA_ExData(CXFA_Document * doc,XFA_PacketType packet)36 CXFA_ExData::CXFA_ExData(CXFA_Document* doc, XFA_PacketType packet)
37     : CXFA_Node(doc,
38                 packet,
39                 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
40                 XFA_ObjectType::ContentNode,
41                 XFA_Element::ExData,
42                 {},
43                 kExDataAttributeData,
44                 cppgc::MakeGarbageCollected<CJX_Object>(
45                     doc->GetHeap()->GetAllocationHandle(),
46                     this)) {}
47 
48 CXFA_ExData::~CXFA_ExData() = default;
49 
SetContentType(const WideString & wsContentType)50 void CXFA_ExData::SetContentType(const WideString& wsContentType) {
51   JSObject()->SetCData(XFA_Attribute::ContentType, wsContentType);
52 }
53