/src/mozilla-central/dom/xml/ProcessingInstruction.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsGkAtoms.h" |
8 | | #include "nsUnicharUtils.h" |
9 | | #include "mozilla/dom/ProcessingInstruction.h" |
10 | | #include "mozilla/dom/ProcessingInstructionBinding.h" |
11 | | #include "mozilla/dom/XMLStylesheetProcessingInstruction.h" |
12 | | #include "mozilla/IntegerPrintfMacros.h" |
13 | | #include "nsContentUtils.h" |
14 | | |
15 | | already_AddRefed<mozilla::dom::ProcessingInstruction> |
16 | | NS_NewXMLProcessingInstruction(nsNodeInfoManager *aNodeInfoManager, |
17 | | const nsAString& aTarget, |
18 | | const nsAString& aData) |
19 | 0 | { |
20 | 0 | using mozilla::dom::ProcessingInstruction; |
21 | 0 | using mozilla::dom::XMLStylesheetProcessingInstruction; |
22 | 0 |
|
23 | 0 | MOZ_ASSERT(aNodeInfoManager, "Missing nodeinfo manager"); |
24 | 0 |
|
25 | 0 | RefPtr<nsAtom> target = NS_Atomize(aTarget); |
26 | 0 | MOZ_ASSERT(target); |
27 | 0 |
|
28 | 0 | if (target == nsGkAtoms::xml_stylesheet) { |
29 | 0 | RefPtr<XMLStylesheetProcessingInstruction> pi = |
30 | 0 | new XMLStylesheetProcessingInstruction(aNodeInfoManager, aData); |
31 | 0 | return pi.forget(); |
32 | 0 | } |
33 | 0 | |
34 | 0 | RefPtr<mozilla::dom::NodeInfo> ni; |
35 | 0 | ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName, |
36 | 0 | nullptr, kNameSpaceID_None, |
37 | 0 | nsINode::PROCESSING_INSTRUCTION_NODE, |
38 | 0 | target); |
39 | 0 |
|
40 | 0 | RefPtr<ProcessingInstruction> instance = |
41 | 0 | new ProcessingInstruction(ni.forget(), aData); |
42 | 0 |
|
43 | 0 | return instance.forget(); |
44 | 0 | } |
45 | | |
46 | | namespace mozilla { |
47 | | namespace dom { |
48 | | |
49 | | ProcessingInstruction::ProcessingInstruction(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
50 | | const nsAString& aData) |
51 | | : CharacterData(std::move(aNodeInfo)) |
52 | 0 | { |
53 | 0 | MOZ_ASSERT(mNodeInfo->NodeType() == nsINode::PROCESSING_INSTRUCTION_NODE, |
54 | 0 | "Bad NodeType in aNodeInfo"); |
55 | 0 |
|
56 | 0 | SetTextInternal(0, mText.GetLength(), |
57 | 0 | aData.BeginReading(), aData.Length(), |
58 | 0 | false); // Don't notify (bug 420429). |
59 | 0 | } |
60 | | |
61 | | ProcessingInstruction::~ProcessingInstruction() |
62 | 0 | { |
63 | 0 | } |
64 | | |
65 | | // If you add nsIStyleSheetLinkingElement here, make sure we actually |
66 | | // implement the nsStyleLinkElement methods. |
67 | | NS_IMPL_ISUPPORTS_INHERITED0(ProcessingInstruction, CharacterData) |
68 | | |
69 | | JSObject* |
70 | | ProcessingInstruction::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) |
71 | 0 | { |
72 | 0 | return ProcessingInstruction_Binding::Wrap(aCx, this, aGivenProto); |
73 | 0 | } |
74 | | |
75 | | bool |
76 | | ProcessingInstruction::GetAttrValue(nsAtom *aName, nsAString& aValue) |
77 | 0 | { |
78 | 0 | nsAutoString data; |
79 | 0 |
|
80 | 0 | GetData(data); |
81 | 0 | return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue); |
82 | 0 | } |
83 | | |
84 | | already_AddRefed<CharacterData> |
85 | | ProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo, |
86 | | bool aCloneText) const |
87 | 0 | { |
88 | 0 | nsAutoString data; |
89 | 0 | GetData(data); |
90 | 0 | RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo; |
91 | 0 | return do_AddRef(new ProcessingInstruction(ni.forget(), data)); |
92 | 0 | } |
93 | | |
94 | | Maybe<nsStyleLinkElement::SheetInfo> |
95 | | ProcessingInstruction::GetStyleSheetInfo() |
96 | 0 | { |
97 | 0 | MOZ_ASSERT_UNREACHABLE("XMLStylesheetProcessingInstruction should override " |
98 | 0 | "this and we don't try to do stylesheet stuff. In " |
99 | 0 | "particular, we do not implement " |
100 | 0 | "nsIStyleSheetLinkingElement"); |
101 | 0 | return Nothing(); |
102 | 0 | } |
103 | | |
104 | | #ifdef DEBUG |
105 | | void |
106 | | ProcessingInstruction::List(FILE* out, int32_t aIndent) const |
107 | | { |
108 | | int32_t index; |
109 | | for (index = aIndent; --index >= 0; ) fputs(" ", out); |
110 | | |
111 | | fprintf(out, "Processing instruction refcount=%" PRIuPTR "<", mRefCnt.get()); |
112 | | |
113 | | nsAutoString tmp; |
114 | | ToCString(tmp, 0, mText.GetLength()); |
115 | | tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0); |
116 | | fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); |
117 | | |
118 | | fputs(">\n", out); |
119 | | } |
120 | | |
121 | | void |
122 | | ProcessingInstruction::DumpContent(FILE* out, int32_t aIndent, |
123 | | bool aDumpAll) const |
124 | | { |
125 | | } |
126 | | #endif |
127 | | |
128 | | } // namespace dom |
129 | | } // namespace mozilla |