Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / xml / ProcessingInstruction.cpp
blob187548721204ab2ea39c2e4cdb1a8a9662ce2dc1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsGkAtoms.h"
8 #include "nsUnicharUtils.h"
9 #include "mozilla/dom/LinkStyle.h"
10 #include "mozilla/dom/ProcessingInstruction.h"
11 #include "mozilla/dom/ProcessingInstructionBinding.h"
12 #include "mozilla/dom/XMLStylesheetProcessingInstruction.h"
13 #include "mozilla/IntegerPrintfMacros.h"
14 #include "nsContentUtils.h"
16 already_AddRefed<mozilla::dom::ProcessingInstruction>
17 NS_NewXMLProcessingInstruction(nsNodeInfoManager* aNodeInfoManager,
18 const nsAString& aTarget,
19 const nsAString& aData) {
20 using mozilla::dom::ProcessingInstruction;
21 using mozilla::dom::XMLStylesheetProcessingInstruction;
23 MOZ_ASSERT(aNodeInfoManager, "Missing nodeinfo manager");
25 RefPtr<nsAtom> target = NS_Atomize(aTarget);
26 MOZ_ASSERT(target);
28 if (target == nsGkAtoms::xml_stylesheet) {
29 RefPtr<XMLStylesheetProcessingInstruction> pi = new (aNodeInfoManager)
30 XMLStylesheetProcessingInstruction(aNodeInfoManager, aData);
31 return pi.forget();
34 RefPtr<mozilla::dom::NodeInfo> ni;
35 ni = aNodeInfoManager->GetNodeInfo(
36 nsGkAtoms::processingInstructionTagName, nullptr, kNameSpaceID_None,
37 nsINode::PROCESSING_INSTRUCTION_NODE, target);
39 RefPtr<ProcessingInstruction> instance =
40 new (aNodeInfoManager) ProcessingInstruction(ni.forget(), aData);
42 return instance.forget();
45 namespace mozilla::dom {
47 ProcessingInstruction::ProcessingInstruction(
48 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
49 const nsAString& aData)
50 : CharacterData(std::move(aNodeInfo)) {
51 MOZ_ASSERT(mNodeInfo->NodeType() == nsINode::PROCESSING_INSTRUCTION_NODE,
52 "Bad NodeType in aNodeInfo");
54 SetTextInternal(0, mText.GetLength(), aData.BeginReading(), aData.Length(),
55 false); // Don't notify (bug 420429).
58 ProcessingInstruction::~ProcessingInstruction() = default;
60 StyleSheet* ProcessingInstruction::GetSheetForBindings() const {
61 if (const auto* linkStyle = LinkStyle::FromNode(*this)) {
62 return linkStyle->GetSheetForBindings();
64 return nullptr;
67 JSObject* ProcessingInstruction::WrapNode(JSContext* aCx,
68 JS::Handle<JSObject*> aGivenProto) {
69 return ProcessingInstruction_Binding::Wrap(aCx, this, aGivenProto);
72 bool ProcessingInstruction::GetAttrValue(nsAtom* aName, nsAString& aValue) {
73 nsAutoString data;
75 GetData(data);
76 return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue);
79 already_AddRefed<CharacterData> ProcessingInstruction::CloneDataNode(
80 mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const {
81 nsAutoString data;
82 GetData(data);
83 RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
84 auto* nim = ni->NodeInfoManager();
85 return do_AddRef(new (nim) ProcessingInstruction(ni.forget(), data));
88 #ifdef MOZ_DOM_LIST
89 void ProcessingInstruction::List(FILE* out, int32_t aIndent) const {
90 int32_t index;
91 for (index = aIndent; --index >= 0;) fputs(" ", out);
93 fprintf(out, "Processing instruction refcount=%" PRIuPTR "<", mRefCnt.get());
95 nsAutoString tmp;
96 ToCString(tmp, 0, mText.GetLength());
97 tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
98 fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
100 fputs(">\n", out);
103 void ProcessingInstruction::DumpContent(FILE* out, int32_t aIndent,
104 bool aDumpAll) const {}
105 #endif
107 } // namespace mozilla::dom