content/base/src/DocumentType.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial