2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-10-21 11:38:41 +04:00
|
|
|
/* 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"
|
|
|
|
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2012-10-21 11:38:41 +04:00
|
|
|
#include "mozilla/dom/DOMImplementationBinding.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-08-22 10:30:55 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2012-12-29 05:34:02 +04:00
|
|
|
#include "DocumentType.h"
|
2013-04-04 16:01:08 +04:00
|
|
|
#include "nsTextNode.h"
|
2012-10-21 11:38:41 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
// QueryInterface implementation for DOMImplementation
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMImplementation)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-03-13 01:31:53 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation)
|
2012-10-21 11:38:41 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2012-10-21 11:38:41 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMImplementation, mOwner)
|
2012-10-21 11:38:41 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMImplementation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMImplementation)
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
DOMImplementation::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-10-21 11:38:41 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return DOMImplementationBinding::Wrap(aCx, this, aGivenProto);
|
2012-10-21 11:38:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMImplementation::HasFeature(const nsAString& aFeature,
|
|
|
|
const nsAString& aVersion)
|
|
|
|
{
|
2013-03-13 01:31:53 +04:00
|
|
|
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;
|
2012-10-21 11:38:41 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 05:34:02 +04:00
|
|
|
already_AddRefed<DocumentType>
|
2012-10-21 11:38:41 +04:00
|
|
|
DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
|
|
|
|
const nsAString& aPublicId,
|
|
|
|
const nsAString& aSystemId,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2012-12-29 05:34:02 +04:00
|
|
|
if (!mOwner) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = nsContentUtils::CheckQName(aQualifiedName);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-29 02:09:43 +03:00
|
|
|
nsCOMPtr<nsIAtom> name = NS_Atomize(aQualifiedName);
|
2012-12-29 05:34:02 +04:00
|
|
|
if (!name) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that there is no internal subset (not just an empty one)
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DocumentType> docType =
|
2012-12-29 05:34:02 +04:00
|
|
|
NS_NewDOMDocumentType(mOwner->NodeInfoManager(), name, aPublicId,
|
|
|
|
aSystemId, NullString(), aRv);
|
|
|
|
return docType.forget();
|
2012-10-21 11:38:41 +04:00
|
|
|
}
|
|
|
|
|
2013-03-13 01:31:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
|
|
|
|
const nsAString& aPublicId,
|
|
|
|
const nsAString& aSystemId,
|
|
|
|
nsIDOMDocumentType** aReturn)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
2014-03-15 23:00:15 +04:00
|
|
|
*aReturn =
|
|
|
|
CreateDocumentType(aQualifiedName, aPublicId, aSystemId, rv).take();
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-03-13 01:31:53 +04:00
|
|
|
}
|
|
|
|
|
2012-10-21 11:38:41 +04:00
|
|
|
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);
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *colon;
|
2012-10-21 11:38:41 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 13:32:29 +04:00
|
|
|
nsCOMPtr<nsIGlobalObject> scriptHandlingObject =
|
2012-10-21 11:38:41 +04:00
|
|
|
do_QueryReferent(mScriptObject);
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> document;
|
|
|
|
|
2012-12-10 18:05:33 +04:00
|
|
|
rv = NS_NewDOMDocument(getter_AddRefs(document),
|
|
|
|
aNamespaceURI, aQualifiedName, aDoctype,
|
|
|
|
mDocumentURI, mBaseURI,
|
|
|
|
mOwner->NodePrincipal(),
|
|
|
|
true, scriptHandlingObject,
|
|
|
|
DocumentFlavorLegacyGuess);
|
2012-10-21 11:38:41 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-27 22:55:44 +04:00
|
|
|
// When DOMImplementation's createDocument method is invoked with
|
|
|
|
// namespace set to HTML Namespace use the registry of the associated
|
|
|
|
// document to the new instance.
|
2012-10-21 11:38:41 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
2016-07-11 08:02:00 +03:00
|
|
|
|
2014-03-27 22:55:44 +04:00
|
|
|
if (aNamespaceURI.EqualsLiteral("http://www.w3.org/1999/xhtml")) {
|
2016-07-11 08:02:00 +03:00
|
|
|
doc->SetContentType(NS_LITERAL_STRING("application/xhtml+xml"));
|
2014-03-27 22:55:44 +04:00
|
|
|
doc->UseRegistryFromDocument(mOwner);
|
2016-07-11 08:02:00 +03:00
|
|
|
} else if (aNamespaceURI.EqualsLiteral("http://www.w3.org/2000/svg")) {
|
|
|
|
doc->SetContentType(NS_LITERAL_STRING("image/svg+xml"));
|
|
|
|
} else {
|
|
|
|
doc->SetContentType(NS_LITERAL_STRING("application/xml"));
|
2014-03-27 22:55:44 +04:00
|
|
|
}
|
|
|
|
|
2012-10-21 11:38:41 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:31:53 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-10-21 11:38:41 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2013-04-04 13:32:29 +04:00
|
|
|
nsCOMPtr<nsIGlobalObject> scriptHandlingObject =
|
2012-10-21 11:38:41 +04:00
|
|
|
do_QueryReferent(mScriptObject);
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(!mScriptObject || scriptHandlingObject);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> document;
|
2012-12-10 18:05:33 +04:00
|
|
|
rv = NS_NewDOMDocument(getter_AddRefs(document),
|
|
|
|
EmptyString(), EmptyString(),
|
|
|
|
doctype, mDocumentURI, mBaseURI,
|
|
|
|
mOwner->NodePrincipal(),
|
|
|
|
true, scriptHandlingObject,
|
|
|
|
DocumentFlavorLegacyGuess);
|
2012-10-21 11:38:41 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
|
|
|
|
|
2015-08-13 14:50:00 +03:00
|
|
|
nsCOMPtr<Element> root = doc->CreateElem(NS_LITERAL_STRING("html"), nullptr,
|
|
|
|
kNameSpaceID_XHTML);
|
2012-10-21 11:38:41 +04:00
|
|
|
rv = doc->AppendChildTo(root, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-08-13 14:50:00 +03:00
|
|
|
nsCOMPtr<Element> head = doc->CreateElem(NS_LITERAL_STRING("head"), nullptr,
|
|
|
|
kNameSpaceID_XHTML);
|
2012-10-21 11:38:41 +04:00
|
|
|
rv = root->AppendChildTo(head, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-03-21 16:55:08 +04:00
|
|
|
if (!DOMStringIsNull(aTitle)) {
|
2015-08-13 14:50:00 +03:00
|
|
|
nsCOMPtr<Element> title = doc->CreateElem(NS_LITERAL_STRING("title"),
|
|
|
|
nullptr, kNameSpaceID_XHTML);
|
2013-03-21 16:55:08 +04:00
|
|
|
rv = head->AppendChildTo(title, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-10-21 11:38:41 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsTextNode> titleText = new nsTextNode(doc->NodeInfoManager());
|
2013-03-21 16:55:08 +04:00
|
|
|
rv = titleText->SetText(aTitle, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = title->AppendChildTo(titleText, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2012-10-21 11:38:41 +04:00
|
|
|
|
2015-08-13 14:50:00 +03:00
|
|
|
nsCOMPtr<Element> body = doc->CreateElem(NS_LITERAL_STRING("body"), nullptr,
|
|
|
|
kNameSpaceID_XHTML);
|
2012-10-21 11:38:41 +04:00
|
|
|
rv = root->AppendChildTo(body, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-27 22:55:44 +04:00
|
|
|
// When the createHTMLDocument method is invoked,
|
|
|
|
// use the registry of the associated document to the new instance.
|
|
|
|
doc->UseRegistryFromDocument(mOwner);
|
|
|
|
|
2012-10-21 11:38:41 +04:00
|
|
|
doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
|
|
|
|
|
|
|
doc.forget(aDocument);
|
|
|
|
document.forget(aDOMDocument);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
2013-03-21 16:55:08 +04:00
|
|
|
DOMImplementation::CreateHTMLDocument(const Optional<nsAString>& aTitle,
|
2012-10-21 11:38:41 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument;
|
2013-03-21 16:55:08 +04:00
|
|
|
aRv = CreateHTMLDocument(aTitle.WasPassed() ? aTitle.Value()
|
|
|
|
: NullString(),
|
|
|
|
getter_AddRefs(document),
|
2012-10-21 11:38:41 +04:00
|
|
|
getter_AddRefs(domDocument));
|
|
|
|
return document.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:31:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMImplementation::CreateHTMLDocument(const nsAString& aTitle,
|
|
|
|
nsIDOMDocument** aReturn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
return CreateHTMLDocument(aTitle, getter_AddRefs(document), aReturn);
|
|
|
|
}
|
|
|
|
|
2012-10-21 11:38:41 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|