Line data Source code
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 9 : NS_NewXMLProcessingInstruction(nsNodeInfoManager *aNodeInfoManager,
17 : const nsAString& aTarget,
18 : const nsAString& aData)
19 : {
20 : using mozilla::dom::ProcessingInstruction;
21 : using mozilla::dom::XMLStylesheetProcessingInstruction;
22 :
23 9 : NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
24 :
25 18 : nsCOMPtr<nsIAtom> target = NS_Atomize(aTarget);
26 9 : MOZ_ASSERT(target);
27 :
28 9 : if (target == nsGkAtoms::xml_stylesheet) {
29 : RefPtr<XMLStylesheetProcessingInstruction> pi =
30 12 : new XMLStylesheetProcessingInstruction(aNodeInfoManager, aData);
31 6 : return pi.forget();
32 : }
33 :
34 6 : RefPtr<mozilla::dom::NodeInfo> ni;
35 6 : ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName,
36 : nullptr, kNameSpaceID_None,
37 : nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
38 3 : target);
39 :
40 : RefPtr<ProcessingInstruction> instance =
41 9 : new ProcessingInstruction(ni.forget(), aData);
42 :
43 3 : return instance.forget();
44 : }
45 :
46 : namespace mozilla {
47 : namespace dom {
48 :
49 9 : ProcessingInstruction::ProcessingInstruction(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
50 9 : const nsAString& aData)
51 9 : : nsGenericDOMDataNode(Move(aNodeInfo))
52 : {
53 9 : MOZ_ASSERT(mNodeInfo->NodeType() == nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
54 : "Bad NodeType in aNodeInfo");
55 :
56 9 : SetTextInternal(0, mText.GetLength(),
57 : aData.BeginReading(), aData.Length(),
58 9 : false); // Don't notify (bug 420429).
59 9 : }
60 :
61 0 : ProcessingInstruction::~ProcessingInstruction()
62 : {
63 0 : }
64 :
65 921 : NS_IMPL_ISUPPORTS_INHERITED(ProcessingInstruction, nsGenericDOMDataNode,
66 : nsIDOMNode, nsIDOMCharacterData,
67 : nsIDOMProcessingInstruction)
68 :
69 : JSObject*
70 0 : ProcessingInstruction::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
71 : {
72 0 : return ProcessingInstructionBinding::Wrap(aCx, this, aGivenProto);
73 : }
74 :
75 : NS_IMETHODIMP
76 0 : ProcessingInstruction::GetTarget(nsAString& aTarget)
77 : {
78 0 : aTarget = NodeName();
79 :
80 0 : return NS_OK;
81 : }
82 :
83 : bool
84 6 : ProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue)
85 : {
86 12 : nsAutoString data;
87 :
88 6 : GetData(data);
89 12 : return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue);
90 : }
91 :
92 : bool
93 45 : ProcessingInstruction::IsNodeOfType(uint32_t aFlags) const
94 : {
95 45 : return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE));
96 : }
97 :
98 : nsGenericDOMDataNode*
99 0 : ProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
100 : bool aCloneText) const
101 : {
102 0 : nsAutoString data;
103 0 : nsGenericDOMDataNode::GetData(data);
104 0 : RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
105 0 : return new ProcessingInstruction(ni.forget(), data);
106 : }
107 :
108 : #ifdef DEBUG
109 : void
110 0 : ProcessingInstruction::List(FILE* out, int32_t aIndent) const
111 : {
112 : int32_t index;
113 0 : for (index = aIndent; --index >= 0; ) fputs(" ", out);
114 :
115 0 : fprintf(out, "Processing instruction refcount=%" PRIuPTR "<", mRefCnt.get());
116 :
117 0 : nsAutoString tmp;
118 0 : ToCString(tmp, 0, mText.GetLength());
119 0 : tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
120 0 : fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
121 :
122 0 : fputs(">\n", out);
123 0 : }
124 :
125 : void
126 0 : ProcessingInstruction::DumpContent(FILE* out, int32_t aIndent,
127 : bool aDumpAll) const
128 : {
129 0 : }
130 : #endif
131 :
132 : } // namespace dom
133 : } // namespace mozilla
|