зеркало из https://github.com/mozilla/gecko-dev.git
Bug 796903 - Part a: Move DOMImplementation to its own file and move it to Paris bindings; r=bz
This commit is contained in:
Родитель
d8e5487689
Коммит
7743757aea
|
@ -0,0 +1,264 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/DOMImplementation.h"
|
||||
|
||||
#include "mozilla/dom/DOMImplementationBinding.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsIDOMDocumentType.h"
|
||||
|
||||
DOMCI_DATA(DOMImplementation, mozilla::dom::DOMImplementation)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// QueryInterface implementation for DOMImplementation
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMImplementation)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMImplementation)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMImplementation)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMImplementation, mOwner)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMImplementation)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMImplementation)
|
||||
|
||||
JSObject*
|
||||
DOMImplementation::WrapObject(JSContext* aCx, JSObject* aScope,
|
||||
bool* aTriedToWrap)
|
||||
{
|
||||
return DOMImplementationBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
||||
}
|
||||
|
||||
bool
|
||||
DOMImplementation::HasFeature(const nsAString& aFeature,
|
||||
const nsAString& aVersion)
|
||||
{
|
||||
return nsContentUtils::InternalIsSupported(
|
||||
static_cast<nsIDOMDOMImplementation*>(this),
|
||||
aFeature, aVersion);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMImplementation::HasFeature(const nsAString& aFeature,
|
||||
const nsAString& aVersion,
|
||||
bool* aReturn)
|
||||
{
|
||||
*aReturn = HasFeature(aFeature, aVersion);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMDocumentType>
|
||||
DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
|
||||
const nsAString& aPublicId,
|
||||
const nsAString& aSystemId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocumentType> doctype;
|
||||
aRv = CreateDocumentType(aQualifiedName, aPublicId, aSystemId,
|
||||
getter_AddRefs(doctype));
|
||||
return doctype.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
|
||||
const nsAString& aPublicId,
|
||||
const nsAString& aSystemId,
|
||||
nsIDOMDocumentType** aReturn)
|
||||
{
|
||||
*aReturn = nullptr;
|
||||
NS_ENSURE_STATE(mOwner);
|
||||
|
||||
nsresult rv = nsContentUtils::CheckQName(aQualifiedName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAtom> name = do_GetAtom(aQualifiedName);
|
||||
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Indicate that there is no internal subset (not just an empty one)
|
||||
return NS_NewDOMDocumentType(aReturn, mOwner->NodeInfoManager(),
|
||||
name, aPublicId,
|
||||
aSystemId, NullString());
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
nsIDocument** aDocument,
|
||||
nsIDOMDocument** aDOMDocument)
|
||||
{
|
||||
*aDocument = nullptr;
|
||||
*aDOMDocument = nullptr;
|
||||
|
||||
nsresult rv;
|
||||
if (!aQualifiedName.IsEmpty()) {
|
||||
const nsAFlatString& qName = PromiseFlatString(aQualifiedName);
|
||||
const PRUnichar *colon;
|
||||
rv = nsContentUtils::CheckQName(qName, true, &colon);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (colon &&
|
||||
(DOMStringIsNull(aNamespaceURI) ||
|
||||
(Substring(qName.get(), colon).EqualsLiteral("xml") &&
|
||||
!aNamespaceURI.EqualsLiteral("http://www.w3.org/XML/1998/namespace")))) {
|
||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
||||
}
|
||||
}
|
||||
else if (DOMStringIsNull(aQualifiedName) &&
|
||||
!DOMStringIsNull(aNamespaceURI)) {
|
||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
|
||||
do_QueryReferent(mScriptObject);
|
||||
|
||||
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
|
||||
rv = nsContentUtils::CreateDocument(aNamespaceURI, aQualifiedName, aDoctype,
|
||||
mDocumentURI, mBaseURI,
|
||||
mOwner->NodePrincipal(),
|
||||
scriptHandlingObject,
|
||||
DocumentFlavorLegacyGuess,
|
||||
getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
||||
doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
||||
|
||||
doc.forget(aDocument);
|
||||
document.forget(aDOMDocument);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
DOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
aRv = CreateDocument(aNamespaceURI, aQualifiedName, aDoctype,
|
||||
getter_AddRefs(document), getter_AddRefs(domDocument));
|
||||
return document.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
nsIDOMDocument** aReturn)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
return CreateDocument(aNamespaceURI, aQualifiedName, aDoctype,
|
||||
getter_AddRefs(document), aReturn);
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
|
||||
nsIDocument** aDocument,
|
||||
nsIDOMDocument** aDOMDocument)
|
||||
{
|
||||
*aDocument = nullptr;
|
||||
*aDOMDocument = nullptr;
|
||||
|
||||
NS_ENSURE_STATE(mOwner);
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentType> doctype;
|
||||
// Indicate that there is no internal subset (not just an empty one)
|
||||
nsresult rv = NS_NewDOMDocumentType(getter_AddRefs(doctype),
|
||||
mOwner->NodeInfoManager(),
|
||||
nsGkAtoms::html, // aName
|
||||
EmptyString(), // aPublicId
|
||||
EmptyString(), // aSystemId
|
||||
NullString()); // aInternalSubset
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
|
||||
do_QueryReferent(mScriptObject);
|
||||
|
||||
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
rv = nsContentUtils::CreateDocument(EmptyString(), EmptyString(),
|
||||
doctype, mDocumentURI, mBaseURI,
|
||||
mOwner->NodePrincipal(),
|
||||
scriptHandlingObject,
|
||||
DocumentFlavorLegacyGuess,
|
||||
getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
||||
|
||||
nsCOMPtr<nsIContent> root;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("html"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(root));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = doc->AppendChildTo(root, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> head;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("head"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(head));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = root->AppendChildTo(head, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> title;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("title"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(title));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = head->AppendChildTo(title, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> titleText;
|
||||
rv = NS_NewTextNode(getter_AddRefs(titleText), doc->NodeInfoManager());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = titleText->SetText(aTitle, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = title->AppendChildTo(titleText, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> body;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("body"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(body));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = root->AppendChildTo(body, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
||||
|
||||
doc.forget(aDocument);
|
||||
document.forget(aDOMDocument);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
DOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
aRv = CreateHTMLDocument(aTitle, getter_AddRefs(document),
|
||||
getter_AddRefs(domDocument));
|
||||
return document.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
|
||||
nsIDOMDocument** aReturn)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
return CreateHTMLDocument(aTitle, getter_AddRefs(document), aReturn);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,98 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_DOMImplementation_h
|
||||
#define mozilla_dom_DOMImplementation_h
|
||||
|
||||
#include "nsIDOMDOMImplementation.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "nsStringGlue.h"
|
||||
|
||||
class nsIDOMDocument;
|
||||
class nsIDOMDocumentType;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class DOMImplementation MOZ_FINAL : public nsIDOMDOMImplementation
|
||||
, public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
DOMImplementation(nsIDocument* aOwner,
|
||||
nsIScriptGlobalObject* aScriptObject,
|
||||
nsIURI* aDocumentURI,
|
||||
nsIURI* aBaseURI)
|
||||
: mOwner(aOwner)
|
||||
, mScriptObject(do_GetWeakReference(aScriptObject))
|
||||
, mDocumentURI(aDocumentURI)
|
||||
, mBaseURI(aBaseURI)
|
||||
{
|
||||
MOZ_ASSERT(aOwner);
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
~DOMImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMImplementation)
|
||||
|
||||
nsIDocument* GetParentObject() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
|
||||
bool* aTriedToWrap) MOZ_OVERRIDE;
|
||||
|
||||
// nsIDOMDOMImplementation
|
||||
NS_DECL_NSIDOMDOMIMPLEMENTATION
|
||||
|
||||
bool HasFeature(const nsAString& aFeature, const nsAString& aVersion);
|
||||
|
||||
already_AddRefed<nsIDOMDocumentType>
|
||||
CreateDocumentType(const nsAString& aQualifiedName,
|
||||
const nsAString& aPublicId,
|
||||
const nsAString& aSystemId,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
CreateHTMLDocument(const nsAString& aTitle, ErrorResult& aRv);
|
||||
|
||||
private:
|
||||
nsresult CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
nsIDocument** aDocument,
|
||||
nsIDOMDocument** aDOMDocument);
|
||||
nsresult CreateHTMLDocument(const nsAString& aTitle,
|
||||
nsIDocument** aDocument,
|
||||
nsIDOMDocument** aDOMDocument);
|
||||
|
||||
nsCOMPtr<nsIDocument> mOwner;
|
||||
nsWeakPtr mScriptObject;
|
||||
nsCOMPtr<nsIURI> mDocumentURI;
|
||||
nsCOMPtr<nsIURI> mBaseURI;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_DOMImplementation_h
|
|
@ -46,11 +46,13 @@ EXPORTS = \
|
|||
EXPORTS_NAMESPACES = mozilla/dom
|
||||
|
||||
EXPORTS_mozilla/dom = \
|
||||
DOMImplementation.h \
|
||||
Link.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
DirectionalityUtils.cpp \
|
||||
DOMImplementation.cpp \
|
||||
nsAtomListUtils.cpp \
|
||||
nsAttrAndChildArray.cpp \
|
||||
nsAttrValue.cpp \
|
||||
|
|
|
@ -160,7 +160,7 @@
|
|||
#include "nsCSPService.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsHTMLCSSStyleSheet.h"
|
||||
|
||||
#include "mozilla/dom/DOMImplementation.h"
|
||||
#include "mozilla/dom/Link.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsDOMTouchEvent.h"
|
||||
|
@ -1277,219 +1277,6 @@ nsDOMStyleSheetSetList::GetSets(nsTArray<nsString>& aStyleSets)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// ==================================================================
|
||||
// =
|
||||
// ==================================================================
|
||||
|
||||
class nsDOMImplementation : public nsIDOMDOMImplementation
|
||||
{
|
||||
public:
|
||||
nsDOMImplementation(nsIDocument* aOwner,
|
||||
nsIScriptGlobalObject* aScriptObject,
|
||||
nsIURI* aDocumentURI,
|
||||
nsIURI* aBaseURI);
|
||||
virtual ~nsDOMImplementation();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMImplementation)
|
||||
|
||||
// nsIDOMDOMImplementation
|
||||
NS_DECL_NSIDOMDOMIMPLEMENTATION
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDocument> mOwner;
|
||||
nsWeakPtr mScriptObject;
|
||||
nsCOMPtr<nsIURI> mDocumentURI;
|
||||
nsCOMPtr<nsIURI> mBaseURI;
|
||||
};
|
||||
|
||||
nsDOMImplementation::nsDOMImplementation(nsIDocument* aOwner,
|
||||
nsIScriptGlobalObject* aScriptObject,
|
||||
nsIURI* aDocumentURI,
|
||||
nsIURI* aBaseURI)
|
||||
: mOwner(aOwner),
|
||||
mScriptObject(do_GetWeakReference(aScriptObject)),
|
||||
mDocumentURI(aDocumentURI),
|
||||
mBaseURI(aBaseURI)
|
||||
{
|
||||
}
|
||||
|
||||
nsDOMImplementation::~nsDOMImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
DOMCI_DATA(DOMImplementation, nsDOMImplementation)
|
||||
|
||||
// QueryInterface implementation for nsDOMImplementation
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMImplementation)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMImplementation)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMImplementation)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(nsDOMImplementation, mOwner)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMImplementation)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMImplementation)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMImplementation::HasFeature(const nsAString& aFeature,
|
||||
const nsAString& aVersion,
|
||||
bool* aReturn)
|
||||
{
|
||||
*aReturn = nsContentUtils::InternalIsSupported(
|
||||
static_cast<nsIDOMDOMImplementation*>(this),
|
||||
aFeature, aVersion);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
|
||||
const nsAString& aPublicId,
|
||||
const nsAString& aSystemId,
|
||||
nsIDOMDocumentType** aReturn)
|
||||
{
|
||||
*aReturn = nullptr;
|
||||
NS_ENSURE_STATE(mOwner);
|
||||
|
||||
nsresult rv = nsContentUtils::CheckQName(aQualifiedName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAtom> name = do_GetAtom(aQualifiedName);
|
||||
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Indicate that there is no internal subset (not just an empty one)
|
||||
return NS_NewDOMDocumentType(aReturn, mOwner->NodeInfoManager(),
|
||||
name, aPublicId,
|
||||
aSystemId, NullString());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
|
||||
const nsAString& aQualifiedName,
|
||||
nsIDOMDocumentType* aDoctype,
|
||||
nsIDOMDocument** aReturn)
|
||||
{
|
||||
*aReturn = nullptr;
|
||||
|
||||
nsresult rv;
|
||||
if (!aQualifiedName.IsEmpty()) {
|
||||
const nsAFlatString& qName = PromiseFlatString(aQualifiedName);
|
||||
const PRUnichar *colon;
|
||||
rv = nsContentUtils::CheckQName(qName, true, &colon);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (colon &&
|
||||
(DOMStringIsNull(aNamespaceURI) ||
|
||||
(Substring(qName.get(), colon).EqualsLiteral("xml") &&
|
||||
!aNamespaceURI.EqualsLiteral("http://www.w3.org/XML/1998/namespace")))) {
|
||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
||||
}
|
||||
}
|
||||
else if (DOMStringIsNull(aQualifiedName) &&
|
||||
!DOMStringIsNull(aNamespaceURI)) {
|
||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
|
||||
do_QueryReferent(mScriptObject);
|
||||
|
||||
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
|
||||
rv = nsContentUtils::CreateDocument(aNamespaceURI, aQualifiedName, aDoctype,
|
||||
mDocumentURI, mBaseURI,
|
||||
mOwner->NodePrincipal(),
|
||||
scriptHandlingObject,
|
||||
DocumentFlavorLegacyGuess,
|
||||
getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
||||
doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
||||
|
||||
document.forget(aReturn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
|
||||
nsIDOMDocument** aReturn)
|
||||
{
|
||||
*aReturn = nullptr;
|
||||
NS_ENSURE_STATE(mOwner);
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentType> doctype;
|
||||
// Indicate that there is no internal subset (not just an empty one)
|
||||
nsresult rv = NS_NewDOMDocumentType(getter_AddRefs(doctype),
|
||||
mOwner->NodeInfoManager(),
|
||||
nsGkAtoms::html, // aName
|
||||
EmptyString(), // aPublicId
|
||||
EmptyString(), // aSystemId
|
||||
NullString()); // aInternalSubset
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
|
||||
do_QueryReferent(mScriptObject);
|
||||
|
||||
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
rv = nsContentUtils::CreateDocument(EmptyString(), EmptyString(),
|
||||
doctype, mDocumentURI, mBaseURI,
|
||||
mOwner->NodePrincipal(),
|
||||
scriptHandlingObject,
|
||||
DocumentFlavorLegacyGuess,
|
||||
getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
||||
|
||||
nsCOMPtr<nsIContent> root;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("html"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(root));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = doc->AppendChildTo(root, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> head;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("head"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(head));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = root->AppendChildTo(head, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> title;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("title"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(title));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = head->AppendChildTo(title, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> titleText;
|
||||
rv = NS_NewTextNode(getter_AddRefs(titleText), doc->NodeInfoManager());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = titleText->SetText(aTitle, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = title->AppendChildTo(titleText, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> body;
|
||||
rv = doc->CreateElem(NS_LITERAL_STRING("body"), NULL, kNameSpaceID_XHTML,
|
||||
getter_AddRefs(body));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = root->AppendChildTo(body, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
||||
|
||||
document.forget(aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ==================================================================
|
||||
// =
|
||||
// ==================================================================
|
||||
|
@ -4501,10 +4288,7 @@ nsDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
|
|||
nsIScriptGlobalObject* scriptObject =
|
||||
GetScriptHandlingObject(hasHadScriptObject);
|
||||
NS_ENSURE_STATE(scriptObject || !hasHadScriptObject);
|
||||
mDOMImplementation = new nsDOMImplementation(this, scriptObject, uri, uri);
|
||||
if (!mDOMImplementation) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mDOMImplementation = new DOMImplementation(this, scriptObject, uri, uri);
|
||||
}
|
||||
|
||||
NS_ADDREF(*aImplementation = mDOMImplementation);
|
||||
|
|
|
@ -621,6 +621,7 @@ addExternalIface('CanvasPattern', headerFile='nsIDOMCanvasRenderingContext2D.h')
|
|||
addExternalIface('ClientRect')
|
||||
addExternalIface('CSSRule')
|
||||
addExternalIface('CSSValue')
|
||||
addExternalIface('DocumentType', nativeType='nsIDOMDocumentType')
|
||||
addExternalIface('DOMStringList', nativeType='nsDOMStringList',
|
||||
headerFile='nsDOMLists.h')
|
||||
addExternalIface('Element', nativeType='nsGenericElement')
|
||||
|
|
|
@ -4,19 +4,26 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.w3.org/TR/2012/WD-dom-20120105/
|
||||
* http://dom.spec.whatwg.org/#interface-domimplementation
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
* Copyright:
|
||||
* To the extent possible under law, the editors have waived all copyright and
|
||||
* related or neighboring rights to this work.
|
||||
*/
|
||||
|
||||
interface Document;
|
||||
interface DocumentType;
|
||||
|
||||
interface DOMImplementation {
|
||||
boolean hasFeature(DOMString feature,
|
||||
[TreatNullAs=EmptyString] DOMString version);
|
||||
|
||||
[Throws]
|
||||
DocumentType createDocumentType(DOMString qualifiedName, DOMString publicId,
|
||||
DOMString systemId);
|
||||
XMLDocument createDocument(DOMString? namespace, DOMString qualifiedName,
|
||||
DocumentType? doctype);
|
||||
[Throws]
|
||||
Document createDocument(DOMString? namespace, DOMString? qualifiedName,
|
||||
DocumentType? doctype);
|
||||
[Throws]
|
||||
Document createHTMLDocument(DOMString title);
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@ webidl_files = \
|
|||
CanvasRenderingContext2D.webidl \
|
||||
ClientRectList.webidl \
|
||||
CSSStyleDeclaration.webidl \
|
||||
DOMImplementation.webidl \
|
||||
DOMTokenList.webidl \
|
||||
DOMSettableTokenList.webidl \
|
||||
Function.webidl \
|
||||
|
|
Загрузка…
Ссылка в новой задаче