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