|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Implementation of DOM Core's nsIDOMDocumentType node. |
|
8 */ |
|
9 |
|
10 #include "mozilla/dom/DocumentType.h" |
|
11 #include "nsGkAtoms.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsDOMString.h" |
|
14 #include "nsNodeInfoManager.h" |
|
15 #include "nsIXPConnect.h" |
|
16 #include "xpcpublic.h" |
|
17 #include "nsWrapperCacheInlines.h" |
|
18 #include "mozilla/dom/DocumentTypeBinding.h" |
|
19 |
|
20 nsresult |
|
21 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, |
|
22 nsNodeInfoManager *aNodeInfoManager, |
|
23 nsIAtom *aName, |
|
24 const nsAString& aPublicId, |
|
25 const nsAString& aSystemId, |
|
26 const nsAString& aInternalSubset) |
|
27 { |
|
28 NS_ENSURE_ARG_POINTER(aDocType); |
|
29 mozilla::ErrorResult rv; |
|
30 *aDocType = NS_NewDOMDocumentType(aNodeInfoManager, aName, aPublicId, |
|
31 aSystemId, aInternalSubset, rv).take(); |
|
32 return rv.ErrorCode(); |
|
33 } |
|
34 |
|
35 already_AddRefed<mozilla::dom::DocumentType> |
|
36 NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager, |
|
37 nsIAtom *aName, |
|
38 const nsAString& aPublicId, |
|
39 const nsAString& aSystemId, |
|
40 const nsAString& aInternalSubset, |
|
41 mozilla::ErrorResult& rv) |
|
42 { |
|
43 if (!aName) { |
|
44 rv.Throw(NS_ERROR_INVALID_POINTER); |
|
45 return nullptr; |
|
46 } |
|
47 |
|
48 already_AddRefed<nsINodeInfo> ni = |
|
49 aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr, |
|
50 kNameSpaceID_None, |
|
51 nsIDOMNode::DOCUMENT_TYPE_NODE, |
|
52 aName); |
|
53 |
|
54 nsRefPtr<mozilla::dom::DocumentType> docType = |
|
55 new mozilla::dom::DocumentType(ni, aPublicId, aSystemId, aInternalSubset); |
|
56 return docType.forget(); |
|
57 } |
|
58 |
|
59 namespace mozilla { |
|
60 namespace dom { |
|
61 |
|
62 JSObject* |
|
63 DocumentType::WrapNode(JSContext *cx) |
|
64 { |
|
65 return DocumentTypeBinding::Wrap(cx, this); |
|
66 } |
|
67 |
|
68 DocumentType::DocumentType(already_AddRefed<nsINodeInfo>& aNodeInfo, |
|
69 const nsAString& aPublicId, |
|
70 const nsAString& aSystemId, |
|
71 const nsAString& aInternalSubset) : |
|
72 DocumentTypeForward(aNodeInfo), |
|
73 mPublicId(aPublicId), |
|
74 mSystemId(aSystemId), |
|
75 mInternalSubset(aInternalSubset) |
|
76 { |
|
77 NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE, |
|
78 "Bad NodeType in aNodeInfo"); |
|
79 } |
|
80 |
|
81 DocumentType::~DocumentType() |
|
82 { |
|
83 } |
|
84 |
|
85 NS_IMPL_ISUPPORTS_INHERITED(DocumentType, nsGenericDOMDataNode, nsIDOMNode, |
|
86 nsIDOMDocumentType) |
|
87 |
|
88 bool |
|
89 DocumentType::IsNodeOfType(uint32_t aFlags) const |
|
90 { |
|
91 // Don't claim to be eDATA_NODE since we're just inheriting |
|
92 // nsGenericDOMDataNode for convinience. Doctypes aren't really |
|
93 // data nodes (they have a null .nodeValue and don't implement |
|
94 // nsIDOMCharacterData) |
|
95 return !(aFlags & ~eCONTENT); |
|
96 } |
|
97 |
|
98 const nsTextFragment* |
|
99 DocumentType::GetText() |
|
100 { |
|
101 return nullptr; |
|
102 } |
|
103 |
|
104 NS_IMETHODIMP |
|
105 DocumentType::GetName(nsAString& aName) |
|
106 { |
|
107 aName = NodeName(); |
|
108 return NS_OK; |
|
109 } |
|
110 |
|
111 NS_IMETHODIMP |
|
112 DocumentType::GetPublicId(nsAString& aPublicId) |
|
113 { |
|
114 aPublicId = mPublicId; |
|
115 |
|
116 return NS_OK; |
|
117 } |
|
118 |
|
119 NS_IMETHODIMP |
|
120 DocumentType::GetSystemId(nsAString& aSystemId) |
|
121 { |
|
122 aSystemId = mSystemId; |
|
123 |
|
124 return NS_OK; |
|
125 } |
|
126 |
|
127 NS_IMETHODIMP |
|
128 DocumentType::GetInternalSubset(nsAString& aInternalSubset) |
|
129 { |
|
130 aInternalSubset = mInternalSubset; |
|
131 return NS_OK; |
|
132 } |
|
133 |
|
134 NS_IMETHODIMP |
|
135 DocumentType::MozRemove() |
|
136 { |
|
137 Remove(); |
|
138 return NS_OK; |
|
139 } |
|
140 |
|
141 nsGenericDOMDataNode* |
|
142 DocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const |
|
143 { |
|
144 already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget(); |
|
145 return new DocumentType(ni, mPublicId, mSystemId, mInternalSubset); |
|
146 } |
|
147 |
|
148 } // namespace dom |
|
149 } // namespace mozilla |
|
150 |