Update DOMImplementation, DocumentType and DOM Error codes to match the current DOM Level 2 recommendation, also make HTML documents have a DocumentType if one is given in the file. r=joki@netscape.com

This commit is contained in:
jst%netscape.com 2000-03-22 22:16:14 +00:00
Родитель 5a866d398c
Коммит 2745ce2c5d
20 изменённых файлов: 576 добавлений и 30 удалений

Просмотреть файл

@ -69,6 +69,7 @@
#include "nsRange.h"
#include "nsIDOMText.h"
#include "nsIDOMComment.h"
#include "nsDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
@ -402,6 +403,15 @@ public:
NS_IMETHOD HasFeature(const nsString& aFeature,
const nsString& aVersion,
PRBool* aReturn);
NS_IMETHOD CreateDocumentType(const nsString& aQualifiedName,
const nsString& aPublicId,
const nsString& aSystemId,
nsIDOMDocumentType** aReturn);
NS_IMETHOD CreateDocument(const nsString& aNamespaceURI,
const nsString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIDOMDocument** aReturn);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
@ -476,6 +486,31 @@ nsDOMImplementation::HasFeature(const nsString& aFeature,
return NS_OK;
}
NS_IMETHODIMP
nsDOMImplementation::CreateDocumentType(const nsString& aQualifiedName,
const nsString& aPublicId,
const nsString& aSystemId,
nsIDOMDocumentType** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
return NS_NewDOMDocumentType(aReturn, aQualifiedName, nsnull, nsnull,
aPublicId, aSystemId, nsAutoString(""));
}
NS_IMETHODIMP
nsDOMImplementation::CreateDocument(const nsString& aNamespaceURI,
const nsString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIDOMDocument** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMImplementation::GetScriptObject(nsIScriptContext *aContext,
void** aScriptObject)
@ -1842,8 +1877,35 @@ nsresult nsDocument::SetScriptObject(void *aScriptObject)
NS_IMETHODIMP
nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER(aDoctype);
*aDoctype = nsnull;
if (mProlog) {
PRInt32 i, count = mProlog->Count();
for (i = 0; i < count; i++) {
nsIContent* content = (nsIContent *)mProlog->ElementAt(0);
if (!content)
continue;
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (node) {
PRUint16 nodeType;
node->GetNodeType(&nodeType);
if (nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) {
return node->QueryInterface(NS_GET_IID(nsIDOMDocumentType),
(void **)aDoctype);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
@ -2270,7 +2332,9 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
if ((COMMENT_NODE != nodeType) &&
(PROCESSING_INSTRUCTION_NODE != nodeType) &&
(DOCUMENT_TYPE_NODE != nodeType)) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
@ -2280,7 +2344,13 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
}
if (nsnull == aRefChild) {
AppendToEpilog(content);
if ((!mProlog || (mProlog && mProlog->Count())) && mRootContent) {
AppendToEpilog(content);
} else if (nodeType != ELEMENT_NODE) {
AppendToProlog(content);
} else {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
else {
result = aRefChild->QueryInterface(kIContentIID, (void**)&refContent);

Просмотреть файл

@ -43,6 +43,8 @@
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIDOMComment.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMWindow.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIStreamListener.h"
@ -1078,6 +1080,78 @@ nsHTMLDocument::AddDocTypeDecl(const nsString& aDocTypeString, nsDTDMode aMode)
mDocTypeStr->Append(aDocTypeString);
}
}
PRInt32 pos = aDocTypeString.Find("public", PR_TRUE);
nsAutoString publicId;
if (pos >= 0) {
aDocTypeString.Mid(publicId, pos + 6, aDocTypeString.Length() - pos);
publicId.CompressWhitespace();
PRUnichar ch = publicId.First();
if (ch == '"' || ch == '\'') {
publicId.Cut(0, 1);
pos = publicId.FindChar(ch);
if (pos >= 0) {
publicId.Truncate(pos);
} else {
publicId.Truncate();
}
}
}
if (publicId.Length()) {
nsCOMPtr<nsIDOMDocumentType> oldDocType;
nsCOMPtr<nsIDOMDocumentType> docType;
GetDoctype(getter_AddRefs(oldDocType));
nsCOMPtr<nsIDOMDOMImplementation> domImpl;
result = GetImplementation(getter_AddRefs(domImpl));
if (NS_FAILED(result) || !domImpl) {
return result;
}
result = domImpl->CreateDocumentType(nsAutoString("html"), publicId,
nsAutoString(""),
getter_AddRefs(docType));
if (NS_FAILED(result) || !docType) {
return result;
}
nsCOMPtr<nsIDOMNode> tmpNode;
if (oldDocType) {
/*
* If we already have a doctype we replace the old one.
*/
result = ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
} else {
/*
* If we don't already have one we insert it as the first child,
* this might not be 100% correct but since this is called from
* the content sink we assume that this is what we want.
*/
nsCOMPtr<nsIDOMNode> firstChild;
GetFirstChild(getter_AddRefs(firstChild));
/*
* If the above fails it must be because we don't have any child
* nodes, then firstChild will be 0 and InsertBefore() will append
*/
result = InsertBefore(docType, firstChild, getter_AddRefs(tmpNode));
}
}
return result;
}
@ -1254,9 +1328,7 @@ nsHTMLDocument::CreateEntityReference(const nsString& aName,
NS_IMETHODIMP
nsHTMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType)
{
// There's no document type for a HTML document
*aDocumentType = nsnull;
return NS_OK;
return nsDocument::GetDoctype(aDocumentType);
}
NS_IMETHODIMP

Просмотреть файл

@ -76,7 +76,10 @@ extern nsresult
NS_NewXMLDocumentType(nsIContent** aInstancePtrResult,
const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations);
nsIDOMNamedNodeMap *aNotations,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString& aInternalSubset);
extern nsresult
NS_NewXMLNamedNodeMap(nsIDOMNamedNodeMap** aInstancePtrResult,

Просмотреть файл

@ -28,6 +28,8 @@
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMDocument;
class nsIDOMDocumentType;
#define NS_IDOMDOMIMPLEMENTATION_IID \
{ 0xa6cf9074, 0x15b3, 0x11d2, \
@ -38,16 +40,24 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMDOMIMPLEMENTATION_IID; return iid; }
NS_IMETHOD HasFeature(const nsString& aFeature, const nsString& aVersion, PRBool* aReturn)=0;
NS_IMETHOD CreateDocumentType(const nsString& aQualifiedName, const nsString& aPublicId, const nsString& aSystemId, nsIDOMDocumentType** aReturn)=0;
NS_IMETHOD CreateDocument(const nsString& aNamespaceURI, const nsString& aQualifiedName, nsIDOMDocumentType* aDoctype, nsIDOMDocument** aReturn)=0;
};
#define NS_DECL_IDOMDOMIMPLEMENTATION \
NS_IMETHOD HasFeature(const nsString& aFeature, const nsString& aVersion, PRBool* aReturn); \
NS_IMETHOD CreateDocumentType(const nsString& aQualifiedName, const nsString& aPublicId, const nsString& aSystemId, nsIDOMDocumentType** aReturn); \
NS_IMETHOD CreateDocument(const nsString& aNamespaceURI, const nsString& aQualifiedName, nsIDOMDocumentType* aDoctype, nsIDOMDocument** aReturn); \
#define NS_FORWARD_IDOMDOMIMPLEMENTATION(_to) \
NS_IMETHOD HasFeature(const nsString& aFeature, const nsString& aVersion, PRBool* aReturn) { return _to HasFeature(aFeature, aVersion, aReturn); } \
NS_IMETHOD CreateDocumentType(const nsString& aQualifiedName, const nsString& aPublicId, const nsString& aSystemId, nsIDOMDocumentType** aReturn) { return _to CreateDocumentType(aQualifiedName, aPublicId, aSystemId, aReturn); } \
NS_IMETHOD CreateDocument(const nsString& aNamespaceURI, const nsString& aQualifiedName, nsIDOMDocumentType* aDoctype, nsIDOMDocument** aReturn) { return _to CreateDocument(aNamespaceURI, aQualifiedName, aDoctype, aReturn); } \
extern "C" NS_DOM nsresult NS_InitDOMImplementationClass(nsIScriptContext *aContext, void **aPrototype);

Просмотреть файл

@ -44,6 +44,12 @@ public:
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities)=0;
NS_IMETHOD GetNotations(nsIDOMNamedNodeMap** aNotations)=0;
NS_IMETHOD GetPublicId(nsString& aPublicId)=0;
NS_IMETHOD GetSystemId(nsString& aSystemId)=0;
NS_IMETHOD GetInternalSubset(nsString& aInternalSubset)=0;
};
@ -51,6 +57,9 @@ public:
NS_IMETHOD GetName(nsString& aName); \
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities); \
NS_IMETHOD GetNotations(nsIDOMNamedNodeMap** aNotations); \
NS_IMETHOD GetPublicId(nsString& aPublicId); \
NS_IMETHOD GetSystemId(nsString& aSystemId); \
NS_IMETHOD GetInternalSubset(nsString& aInternalSubset); \
@ -58,6 +67,9 @@ public:
NS_IMETHOD GetName(nsString& aName) { return _to GetName(aName); } \
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities) { return _to GetEntities(aEntities); } \
NS_IMETHOD GetNotations(nsIDOMNamedNodeMap** aNotations) { return _to GetNotations(aNotations); } \
NS_IMETHOD GetPublicId(nsString& aPublicId) { return _to GetPublicId(aPublicId); } \
NS_IMETHOD GetSystemId(nsString& aSystemId) { return _to GetSystemId(aSystemId); } \
NS_IMETHOD GetInternalSubset(nsString& aInternalSubset) { return _to GetInternalSubset(aInternalSubset); } \
extern "C" NS_DOM nsresult NS_InitDocumentTypeClass(nsIScriptContext *aContext, void **aPrototype);

Просмотреть файл

@ -4,4 +4,14 @@
boolean hasFeature(in DOMString feature,
in DOMString version);
DocumentType createDocumentType(in DOMString qualifiedName,
in DOMString publicId,
in DOMString systemId)
raises(DOMException);
Document createDocument(in DOMString namespaceURI,
in DOMString qualifiedName,
in DocumentType doctype)
raises(DOMException);
};

Просмотреть файл

@ -5,4 +5,7 @@
readonly attribute DOMString name;
readonly attribute NamedNodeMap entities;
readonly attribute NamedNodeMap notations;
readonly attribute DOMString publicId;
readonly attribute DOMString systemId;
readonly attribute DOMString internalSubset;
};

Просмотреть файл

@ -41,6 +41,14 @@
#define NS_ERROR_DOM_NOT_SUPPORTED_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,9)
#define NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,10)
/* DOM error codes from http://www.w3.org/TR/DOM-Level-2/ */
#define NS_ERROR_DOM_INVALID_ACCESS_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,11)
#define NS_ERROR_DOM_INVALID_MODIFICATION_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,12)
#define NS_ERROR_DOM_INVALID_STATE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,13)
#define NS_ERROR_DOM_NAMESPACE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,14)
#define NS_ERROR_DOM_SYNTAX_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,15)
/* DOM error codes defined by us */
#define NS_ERROR_DOM_SECURITY_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,1000)

Просмотреть файл

@ -220,12 +220,17 @@ enum nsDOMProp {
NS_DOM_PROP_DOCUMENTTYPE_ENTITIES,
NS_DOM_PROP_DOCUMENTTYPE_NAME,
NS_DOM_PROP_DOCUMENTTYPE_NOTATIONS,
NS_DOM_PROP_DOCUMENTTYPE_PUBLICID,
NS_DOM_PROP_DOCUMENTTYPE_SYSTEMID,
NS_DOM_PROP_DOCUMENTTYPE_INTERNALSUBSET,
NS_DOM_PROP_DOMEXCEPTION_CODE,
NS_DOM_PROP_DOMEXCEPTION_MESSAGE,
NS_DOM_PROP_DOMEXCEPTION_NAME,
NS_DOM_PROP_DOMEXCEPTION_RESULT,
NS_DOM_PROP_DOMEXCEPTION_TOSTRING,
NS_DOM_PROP_DOMIMPLEMENTATION_HASFEATURE,
NS_DOM_PROP_DOMIMPLEMENTATION_CREATEDOCUMENTTYPE,
NS_DOM_PROP_DOMIMPLEMENTATION_CREATEDOCUMENT,
NS_DOM_PROP_ELEMENT_GETATTRIBUTE,
NS_DOM_PROP_ELEMENT_GETATTRIBUTENODE,
NS_DOM_PROP_ELEMENT_GETELEMENTSBYTAGNAME,

Просмотреть файл

@ -219,12 +219,17 @@
"documenttype.entities", \
"documenttype.name", \
"documenttype.notations", \
"documenttype.publicid", \
"documenttype.systemid", \
"documenttype.internalsubset", \
"domexception.code", \
"domexception.message", \
"domexception.name", \
"domexception.result", \
"domexception.tostring", \
"domimplementation.hasfeature", \
"domimplementation.createdocumenttype", \
"domimplementation.createdocument", \
"element.getattribute", \
"element.getattributenode", \
"element.getelementsbytagname", \
@ -651,11 +656,11 @@
"navigator.language", \
"navigator.mimetypes", \
"navigator.platform", \
"navigator.oscpu", \
"navigator.vendor", \
"navigator.vendorSub", \
"navigator.vendorsub", \
"navigator.product", \
"navigator.productSub", \
"navigator.productsub", \
"navigator.oscpu", \
"navigator.plugins", \
"navigator.preference", \
"navigator.securitypolicy", \

Просмотреть файл

@ -36,6 +36,14 @@ DOM_MSG_DEF(NS_ERROR_DOM_NOT_FOUND_ERR, "Node was not found")
DOM_MSG_DEF(NS_ERROR_DOM_NOT_SUPPORTED_ERR, "Object cannot be created in this context")
DOM_MSG_DEF(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR, "Attribute already in use")
/* DOM error codes from http://www.w3.org/TR/DOM-Level-2/ */
DOM_MSG_DEF(NS_ERROR_DOM_INVALID_ACCESS_ERR, "A parameter or an operation is not supported by the underlying object")
DOM_MSG_DEF(NS_ERROR_DOM_INVALID_MODIFICATION_ERR, "An attempt was made to modify the type of the underlying objec")
DOM_MSG_DEF(NS_ERROR_DOM_INVALID_STATE_ERR, "An attempt was made to use an object that is not, or is no longer, usable")
DOM_MSG_DEF(NS_ERROR_DOM_NAMESPACE_ERR, "An attempt was made to create or change an object in a way which is incorrect with regard to namespaces")
DOM_MSG_DEF(NS_ERROR_DOM_SYNTAX_ERR, "An invalid or illegal string was specified")
/* DOM error codes defined by us */
/* XXX string should be specified by norris */

Просмотреть файл

@ -369,6 +369,9 @@ nsDOMScriptObjectFactory::NewScriptCharacterData(PRUint16 aNodeType,
else if (aNodeType == nsIDOMNode::COMMENT_NODE) {
return NS_NewScriptComment(aContext, aData, aParent, aReturn);
}
else if (aNodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) {
return NS_NewScriptDocumentType(aContext, aData, aParent, aReturn);
}
else {
return NS_NewScriptText(aContext, aData, aParent, aReturn);
}

Просмотреть файл

@ -34,13 +34,17 @@
#include "nsCOMPtr.h"
#include "nsDOMPropEnums.h"
#include "nsString.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID);
static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
/***********************************************************************/
@ -186,6 +190,104 @@ DOMImplementationHasFeature(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
}
//
// Native method CreateDocumentType
//
PR_STATIC_CALLBACK(JSBool)
DOMImplementationCreateDocumentType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDOMImplementation *nativeThis = (nsIDOMDOMImplementation*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMDocumentType* nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOMIMPLEMENTATION_CREATEDOCUMENTTYPE, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 3) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
result = nativeThis->CreateDocumentType(b0, b1, b2, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval);
}
return JS_TRUE;
}
//
// Native method CreateDocument
//
PR_STATIC_CALLBACK(JSBool)
DOMImplementationCreateDocument(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDOMImplementation *nativeThis = (nsIDOMDOMImplementation*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMDocument* nativeRet;
nsAutoString b0;
nsAutoString b1;
nsCOMPtr<nsIDOMDocumentType> b2;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOMIMPLEMENTATION_CREATEDOCUMENT, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 3) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b2),
kIDocumentTypeIID,
"DocumentType",
cx,
argv[2])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->CreateDocument(b0, b1, b2, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval);
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for DOMImplementation
@ -221,6 +323,8 @@ static JSPropertySpec DOMImplementationProperties[] =
static JSFunctionSpec DOMImplementationMethods[] =
{
{"hasFeature", DOMImplementationHasFeature, 2},
{"createDocumentType", DOMImplementationCreateDocumentType, 3},
{"createDocument", DOMImplementationCreateDocument, 3},
{0}
};

Просмотреть файл

@ -50,7 +50,10 @@ static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
enum DocumentType_slots {
DOCUMENTTYPE_NAME = -1,
DOCUMENTTYPE_ENTITIES = -2,
DOCUMENTTYPE_NOTATIONS = -3
DOCUMENTTYPE_NOTATIONS = -3,
DOCUMENTTYPE_PUBLICID = -4,
DOCUMENTTYPE_SYSTEMID = -5,
DOCUMENTTYPE_INTERNALSUBSET = -6
};
/***********************************************************************/
@ -111,6 +114,42 @@ GetDocumentTypeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case DOCUMENTTYPE_PUBLICID:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTTYPE_PUBLICID, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsAutoString prop;
rv = a->GetPublicId(prop);
if (NS_SUCCEEDED(rv)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
}
break;
}
case DOCUMENTTYPE_SYSTEMID:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTTYPE_SYSTEMID, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsAutoString prop;
rv = a->GetSystemId(prop);
if (NS_SUCCEEDED(rv)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
}
break;
}
case DOCUMENTTYPE_INTERNALSUBSET:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTTYPE_INTERNALSUBSET, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsAutoString prop;
rv = a->GetInternalSubset(prop);
if (NS_SUCCEEDED(rv)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -217,6 +256,9 @@ static JSPropertySpec DocumentTypeProperties[] =
{"name", DOCUMENTTYPE_NAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{"entities", DOCUMENTTYPE_ENTITIES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"notations", DOCUMENTTYPE_NOTATIONS, JSPROP_ENUMERATE | JSPROP_READONLY},
{"publicId", DOCUMENTTYPE_PUBLICID, JSPROP_ENUMERATE | JSPROP_READONLY},
{"systemId", DOCUMENTTYPE_SYSTEMID, JSPROP_ENUMERATE | JSPROP_READONLY},
{"internalSubset", DOCUMENTTYPE_INTERNALSUBSET, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};

Просмотреть файл

@ -40,6 +40,7 @@ CPPSRCS = \
nsDocumentViewer.cpp \
nsDOMAttribute.cpp \
nsDOMAttributeMap.cpp \
nsDOMDocumentType.cpp \
nsFrameImageLoader.cpp \
nsFrameList.cpp \
nsFrameTraversal.cpp \

Просмотреть файл

@ -40,6 +40,7 @@ CPPSRCS = \
nsDocumentViewer.cpp \
nsDOMAttribute.cpp \
nsDOMAttributeMap.cpp \
nsDOMDocumentType.cpp \
nsFrameImageLoader.cpp \
nsFrameList.cpp \
nsFrameTraversal.cpp \
@ -86,6 +87,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsDocumentViewer.obj \
.\$(OBJDIR)\nsDOMAttribute.obj \
.\$(OBJDIR)\nsDOMAttributeMap.obj \
.\$(OBJDIR)\nsDOMDocumentType.obj \
.\$(OBJDIR)\nsFrameImageLoader.obj \
.\$(OBJDIR)\nsFrameList.obj \
.\$(OBJDIR)\nsFrameTraversal.obj \

Просмотреть файл

@ -69,6 +69,7 @@
#include "nsRange.h"
#include "nsIDOMText.h"
#include "nsIDOMComment.h"
#include "nsDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
@ -402,6 +403,15 @@ public:
NS_IMETHOD HasFeature(const nsString& aFeature,
const nsString& aVersion,
PRBool* aReturn);
NS_IMETHOD CreateDocumentType(const nsString& aQualifiedName,
const nsString& aPublicId,
const nsString& aSystemId,
nsIDOMDocumentType** aReturn);
NS_IMETHOD CreateDocument(const nsString& aNamespaceURI,
const nsString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIDOMDocument** aReturn);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
@ -476,6 +486,31 @@ nsDOMImplementation::HasFeature(const nsString& aFeature,
return NS_OK;
}
NS_IMETHODIMP
nsDOMImplementation::CreateDocumentType(const nsString& aQualifiedName,
const nsString& aPublicId,
const nsString& aSystemId,
nsIDOMDocumentType** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
return NS_NewDOMDocumentType(aReturn, aQualifiedName, nsnull, nsnull,
aPublicId, aSystemId, nsAutoString(""));
}
NS_IMETHODIMP
nsDOMImplementation::CreateDocument(const nsString& aNamespaceURI,
const nsString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIDOMDocument** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMImplementation::GetScriptObject(nsIScriptContext *aContext,
void** aScriptObject)
@ -1842,8 +1877,35 @@ nsresult nsDocument::SetScriptObject(void *aScriptObject)
NS_IMETHODIMP
nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER(aDoctype);
*aDoctype = nsnull;
if (mProlog) {
PRInt32 i, count = mProlog->Count();
for (i = 0; i < count; i++) {
nsIContent* content = (nsIContent *)mProlog->ElementAt(0);
if (!content)
continue;
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (node) {
PRUint16 nodeType;
node->GetNodeType(&nodeType);
if (nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) {
return node->QueryInterface(NS_GET_IID(nsIDOMDocumentType),
(void **)aDoctype);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
@ -2270,7 +2332,9 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
if ((COMMENT_NODE != nodeType) &&
(PROCESSING_INSTRUCTION_NODE != nodeType) &&
(DOCUMENT_TYPE_NODE != nodeType)) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
@ -2280,7 +2344,13 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
}
if (nsnull == aRefChild) {
AppendToEpilog(content);
if ((!mProlog || (mProlog && mProlog->Count())) && mRootContent) {
AppendToEpilog(content);
} else if (nodeType != ELEMENT_NODE) {
AppendToProlog(content);
} else {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
else {
result = aRefChild->QueryInterface(kIContentIID, (void**)&refContent);

Просмотреть файл

@ -43,6 +43,8 @@
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIDOMComment.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMWindow.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIStreamListener.h"
@ -1078,6 +1080,78 @@ nsHTMLDocument::AddDocTypeDecl(const nsString& aDocTypeString, nsDTDMode aMode)
mDocTypeStr->Append(aDocTypeString);
}
}
PRInt32 pos = aDocTypeString.Find("public", PR_TRUE);
nsAutoString publicId;
if (pos >= 0) {
aDocTypeString.Mid(publicId, pos + 6, aDocTypeString.Length() - pos);
publicId.CompressWhitespace();
PRUnichar ch = publicId.First();
if (ch == '"' || ch == '\'') {
publicId.Cut(0, 1);
pos = publicId.FindChar(ch);
if (pos >= 0) {
publicId.Truncate(pos);
} else {
publicId.Truncate();
}
}
}
if (publicId.Length()) {
nsCOMPtr<nsIDOMDocumentType> oldDocType;
nsCOMPtr<nsIDOMDocumentType> docType;
GetDoctype(getter_AddRefs(oldDocType));
nsCOMPtr<nsIDOMDOMImplementation> domImpl;
result = GetImplementation(getter_AddRefs(domImpl));
if (NS_FAILED(result) || !domImpl) {
return result;
}
result = domImpl->CreateDocumentType(nsAutoString("html"), publicId,
nsAutoString(""),
getter_AddRefs(docType));
if (NS_FAILED(result) || !docType) {
return result;
}
nsCOMPtr<nsIDOMNode> tmpNode;
if (oldDocType) {
/*
* If we already have a doctype we replace the old one.
*/
result = ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
} else {
/*
* If we don't already have one we insert it as the first child,
* this might not be 100% correct but since this is called from
* the content sink we assume that this is what we want.
*/
nsCOMPtr<nsIDOMNode> firstChild;
GetFirstChild(getter_AddRefs(firstChild));
/*
* If the above fails it must be because we don't have any child
* nodes, then firstChild will be 0 and InsertBefore() will append
*/
result = InsertBefore(docType, firstChild, getter_AddRefs(tmpNode));
}
}
return result;
}
@ -1254,9 +1328,7 @@ nsHTMLDocument::CreateEntityReference(const nsString& aName,
NS_IMETHODIMP
nsHTMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType)
{
// There's no document type for a HTML document
*aDocumentType = nsnull;
return NS_OK;
return nsDocument::GetDoctype(aDocumentType);
}
NS_IMETHODIMP

Просмотреть файл

@ -76,7 +76,10 @@ extern nsresult
NS_NewXMLDocumentType(nsIContent** aInstancePtrResult,
const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations);
nsIDOMNamedNodeMap *aNotations,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString& aInternalSubset);
extern nsresult
NS_NewXMLNamedNodeMap(nsIDOMNamedNodeMap** aInstancePtrResult,

Просмотреть файл

@ -41,9 +41,13 @@ class nsXMLDocumentType : public nsIDOMDocumentType,
public nsIContent
{
public:
nsXMLDocumentType(const nsString& aTarget,
nsXMLDocumentType(const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations);
nsIDOMNamedNodeMap *aNotations,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString& aInternalSubset);
virtual ~nsXMLDocumentType();
// nsISupports
@ -53,9 +57,7 @@ public:
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMDocumentType
NS_IMETHOD GetName(nsString& aName);
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities);
NS_IMETHOD GetNotations(nsIDOMNamedNodeMap** aNotations);
NS_DECL_IDOMDOCUMENTTYPE
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
@ -75,6 +77,9 @@ protected:
nsString mName;
nsIDOMNamedNodeMap* mEntities;
nsIDOMNamedNodeMap* mNotations;
nsString mPublicId;
nsString mSystemId;
nsString mInternalSubset;
void* mScriptObject;
};
@ -82,13 +87,18 @@ nsresult
NS_NewXMLDocumentType(nsIContent** aInstancePtrResult,
const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations)
nsIDOMNamedNodeMap *aNotations,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString& aInternalSubset)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLDocumentType(aName, aEntities, aNotations);
nsIContent* it = new nsXMLDocumentType(aName, aEntities, aNotations,
aPublicId, aSystemId, aInternalSubset);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -97,8 +107,14 @@ NS_NewXMLDocumentType(nsIContent** aInstancePtrResult,
nsXMLDocumentType::nsXMLDocumentType(const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations) :
mName(aName)
nsIDOMNamedNodeMap *aNotations,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString& aInternalSubset) :
mName(aName),
mPublicId(aPublicId),
mSystemId(aSystemId),
mInternalSubset(aInternalSubset)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
@ -201,6 +217,30 @@ nsXMLDocumentType::GetNotations(nsIDOMNamedNodeMap** aNotations)
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetPublicId(nsString& aPublicId)
{
aPublicId = mPublicId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetSystemId(nsString& aSystemId)
{
aSystemId = mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetInternalSubset(nsString& aInternalSubset)
{
aInternalSubset = mInternalSubset;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
@ -266,7 +306,10 @@ nsXMLDocumentType::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
nsXMLDocumentType* it = new nsXMLDocumentType(mName,
mEntities,
mNotations);
mNotations,
mPublicId,
mSystemId,
mInternalSubset);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}