diff --git a/mozilla/dom/src/coreDOM/nsJSDocumentStyle.cpp b/mozilla/dom/src/coreDOM/nsJSDocumentStyle.cpp new file mode 100644 index 00000000000..267cc6ce677 --- /dev/null +++ b/mozilla/dom/src/coreDOM/nsJSDocumentStyle.cpp @@ -0,0 +1,1227 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nsDOMError.h" +#include "nscore.h" +#include "nsIServiceManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptSecurityManager.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsCOMPtr.h" +#include "nsDOMPropEnums.h" +#include "nsString.h" +#include "nsIDOMElement.h" +#include "nsIDOMAttr.h" +#include "nsIDOMDocument.h" +#include "nsIDOMProcessingInstruction.h" +#include "nsIDOMNode.h" +#include "nsIDOMCDATASection.h" +#include "nsIDOMText.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMDocumentType.h" +#include "nsIDOMEntityReference.h" +#include "nsIDOMNSDocument.h" +#include "nsIDOMDocumentStyle.h" +#include "nsIDOMComment.h" +#include "nsIDOMDocumentFragment.h" +#include "nsIDOMRange.h" +#include "nsIDOMNodeList.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(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIAttrIID, NS_IDOMATTR_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID); +static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID); +static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID); +static NS_DEFINE_IID(kIEntityReferenceIID, NS_IDOMENTITYREFERENCE_IID); +static NS_DEFINE_IID(kINSDocumentIID, NS_IDOMNSDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentStyleIID, NS_IDOMDOCUMENTSTYLE_IID); +static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID); +static NS_DEFINE_IID(kIDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID); +static NS_DEFINE_IID(kIRangeIID, NS_IDOMRANGE_IID); +static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID); + +// +// Document property ids +// +enum Document_slots { + DOCUMENT_DOCTYPE = -1, + DOCUMENT_IMPLEMENTATION = -2, + DOCUMENT_DOCUMENTELEMENT = -3, + NSDOCUMENT_WIDTH = -4, + NSDOCUMENT_HEIGHT = -5, + NSDOCUMENT_CHARACTERSET = -6 +}; + +/***********************************************************************/ +// +// DocumentStyle Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetDocumentStyleProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentStyle *a = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case DOCUMENT_DOCTYPE: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_DOCTYPE, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMDocumentType* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetDoctype(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENT_IMPLEMENTATION: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_IMPLEMENTATION, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMDOMImplementation* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetImplementation(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENT_DOCUMENTELEMENT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_DOCUMENTELEMENT, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMElement* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetDocumentElement(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_WIDTH: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_WIDTH, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRInt32 prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetWidth(&prop); + if(NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_HEIGHT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_HEIGHT, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRInt32 prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetHeight(&prop); + if(NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_CHARACTERSET: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_CHARACTERSET, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsAutoString prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetCharacterSet(prop); + if(NS_SUCCEEDED(rv)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + default: + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + +/***********************************************************************/ +// +// DocumentStyle Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetDocumentStyleProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentStyle *a = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + + +// +// DocumentStyle finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeDocumentStyle(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// DocumentStyle enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateDocumentStyle(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// DocumentStyle resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveDocumentStyle(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method CreateElement +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEELEMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateElement(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateDocumentFragment +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateDocumentFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMDocumentFragment* nativeRet; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEDOCUMENTFRAGMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + result = nativeThis->CreateDocumentFragment(&nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateTextNode +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateTextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMText* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATETEXTNODE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateTextNode(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateComment +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMComment* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATECOMMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateComment(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateCDATASection +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateCDATASection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMCDATASection* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATECDATASECTION, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateCDATASection(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateProcessingInstruction +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateProcessingInstruction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMProcessingInstruction* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEPROCESSINGINSTRUCTION, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateProcessingInstruction(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateAttribute +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMAttr* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEATTRIBUTE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateAttribute(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateEntityReference +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateEntityReference(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMEntityReference* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEENTITYREFERENCE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateEntityReference(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagName +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNodeList* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTSBYTAGNAME, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->GetElementsByTagName(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method ImportNode +// +PR_STATIC_CALLBACK(JSBool) +DocumentImportNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNode* nativeRet; + nsCOMPtr b0; + PRBool b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_IMPORTNODE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0), + kINodeIID, + "Node", + cx, + argv[0])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR); + } + if (!nsJSUtils::nsConvertJSValToBool(&b1, cx, argv[1])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_BOOLEAN_ERR); + } + + result = nativeThis->ImportNode(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateElementNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateElementNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEELEMENTNS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateElementNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMAttr* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateAttributeNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagNameNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementsByTagNameNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNodeList* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTSBYTAGNAMENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->GetElementsByTagNameNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementById +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTBYID, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->GetElementById(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateElementWithNameSpace +// +PR_STATIC_CALLBACK(JSBool) +NSDocumentCreateElementWithNameSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kINSDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_NSDOCUMENT_CREATEELEMENTWITHNAMESPACE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateElementWithNameSpace(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateRange +// +PR_STATIC_CALLBACK(JSBool) +NSDocumentCreateRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentStyle *privateThis = (nsIDOMDocumentStyle*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kINSDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMRange* nativeRet; + // If there's no private data, this must be the prototype, so ignore + if (!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_NSDOCUMENT_CREATERANGE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + result = nativeThis->CreateRange(&nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for DocumentStyle +// +JSClass DocumentStyleClass = { + "DocumentStyle", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetDocumentStyleProperty, + SetDocumentStyleProperty, + EnumerateDocumentStyle, + ResolveDocumentStyle, + JS_ConvertStub, + FinalizeDocumentStyle, + nsnull, + nsJSUtils::nsCheckAccess +}; + + +// +// DocumentStyle class properties +// +static JSPropertySpec DocumentStyleProperties[] = +{ + {"doctype", DOCUMENT_DOCTYPE, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"implementation", DOCUMENT_IMPLEMENTATION, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"width", NSDOCUMENT_WIDTH, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"height", NSDOCUMENT_HEIGHT, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"characterSet", NSDOCUMENT_CHARACTERSET, JSPROP_ENUMERATE | JSPROP_READONLY}, + {0} +}; + + +// +// DocumentStyle class methods +// +static JSFunctionSpec DocumentStyleMethods[] = +{ + {"createElement", DocumentCreateElement, 1}, + {"createDocumentFragment", DocumentCreateDocumentFragment, 0}, + {"createTextNode", DocumentCreateTextNode, 1}, + {"createComment", DocumentCreateComment, 1}, + {"createCDATASection", DocumentCreateCDATASection, 1}, + {"createProcessingInstruction", DocumentCreateProcessingInstruction, 2}, + {"createAttribute", DocumentCreateAttribute, 1}, + {"createEntityReference", DocumentCreateEntityReference, 1}, + {"getElementsByTagName", DocumentGetElementsByTagName, 1}, + {"importNode", DocumentImportNode, 2}, + {"createElementNS", DocumentCreateElementNS, 2}, + {"createAttributeNS", DocumentCreateAttributeNS, 2}, + {"getElementsByTagNameNS", DocumentGetElementsByTagNameNS, 2}, + {"getElementById", DocumentGetElementById, 1}, + {"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2}, + {"createRange", NSDocumentCreateRange, 0}, + {0} +}; + + +// +// DocumentStyle constructor +// +PR_STATIC_CALLBACK(JSBool) +DocumentStyle(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_FALSE; +} + + +// +// DocumentStyle class initialization +// +extern "C" NS_DOM nsresult NS_InitDocumentStyleClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentStyle", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DocumentStyleClass, // JSClass + DocumentStyle, // JSNative ctor + 0, // ctor args + DocumentStyleProperties, // proto props + DocumentStyleMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new DocumentStyle JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptDocumentStyle(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentStyle"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMDocumentStyle *aDocumentStyle; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDocumentStyleClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIDocumentStyleIID, (void **)&aDocumentStyle); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &DocumentStyleClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aDocumentStyle); + } + else { + NS_RELEASE(aDocumentStyle); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/coreDOM/nsJSDocumentView.cpp b/mozilla/dom/src/coreDOM/nsJSDocumentView.cpp new file mode 100644 index 00000000000..06a7dc0cd43 --- /dev/null +++ b/mozilla/dom/src/coreDOM/nsJSDocumentView.cpp @@ -0,0 +1,1277 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nsDOMError.h" +#include "nscore.h" +#include "nsIServiceManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptSecurityManager.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsCOMPtr.h" +#include "nsDOMPropEnums.h" +#include "nsString.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocumentView.h" +#include "nsIDOMAttr.h" +#include "nsIDOMDocument.h" +#include "nsIDOMProcessingInstruction.h" +#include "nsIDOMAbstractView.h" +#include "nsIDOMNode.h" +#include "nsIDOMCDATASection.h" +#include "nsIDOMText.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMDocumentType.h" +#include "nsIDOMStyleSheetList.h" +#include "nsIDOMEntityReference.h" +#include "nsIDOMNSDocument.h" +#include "nsIDOMDocumentStyle.h" +#include "nsIDOMComment.h" +#include "nsIDOMDocumentFragment.h" +#include "nsIDOMRange.h" +#include "nsIDOMNodeList.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(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDocumentViewIID, NS_IDOMDOCUMENTVIEW_IID); +static NS_DEFINE_IID(kIAttrIID, NS_IDOMATTR_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_IID); +static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID); +static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID); +static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID); +static NS_DEFINE_IID(kIStyleSheetListIID, NS_IDOMSTYLESHEETLIST_IID); +static NS_DEFINE_IID(kIEntityReferenceIID, NS_IDOMENTITYREFERENCE_IID); +static NS_DEFINE_IID(kINSDocumentIID, NS_IDOMNSDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentStyleIID, NS_IDOMDOCUMENTSTYLE_IID); +static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID); +static NS_DEFINE_IID(kIDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID); +static NS_DEFINE_IID(kIRangeIID, NS_IDOMRANGE_IID); +static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID); + +// +// Document property ids +// +enum Document_slots { + DOCUMENT_DOCTYPE = -1, + DOCUMENT_IMPLEMENTATION = -2, + DOCUMENT_DOCUMENTELEMENT = -3, + DOCUMENTSTYLE_STYLESHEETS = -4, + DOCUMENTVIEW_DEFAULTVIEW = -5, + NSDOCUMENT_WIDTH = -6, + NSDOCUMENT_HEIGHT = -7, + NSDOCUMENT_CHARACTERSET = -8 +}; + +/***********************************************************************/ +// +// DocumentView Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetDocumentViewProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentView *a = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case DOCUMENT_DOCTYPE: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_DOCTYPE, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMDocumentType* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetDoctype(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENT_IMPLEMENTATION: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_IMPLEMENTATION, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMDOMImplementation* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetImplementation(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENT_DOCUMENTELEMENT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENT_DOCUMENTELEMENT, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMElement* prop; + nsIDOMDocument* b; + if (NS_OK == a->QueryInterface(kIDocumentIID, (void **)&b)) { + rv = b->GetDocumentElement(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENTSTYLE_STYLESHEETS: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTSTYLE_STYLESHEETS, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMStyleSheetList* prop; + nsIDOMDocumentStyle* b; + if (NS_OK == a->QueryInterface(kIDocumentStyleIID, (void **)&b)) { + rv = b->GetStyleSheets(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case DOCUMENTVIEW_DEFAULTVIEW: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTVIEW_DEFAULTVIEW, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMAbstractView* prop; + nsIDOMDocumentView* b; + if (NS_OK == a->QueryInterface(kIDocumentViewIID, (void **)&b)) { + rv = b->GetDefaultView(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_WIDTH: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_WIDTH, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRInt32 prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetWidth(&prop); + if(NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_HEIGHT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_HEIGHT, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRInt32 prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetHeight(&prop); + if(NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + case NSDOCUMENT_CHARACTERSET: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_CHARACTERSET, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsAutoString prop; + nsIDOMNSDocument* b; + if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) { + rv = b->GetCharacterSet(prop); + if(NS_SUCCEEDED(rv)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } + default: + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + +/***********************************************************************/ +// +// DocumentView Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetDocumentViewProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentView *a = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + + +// +// DocumentView finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeDocumentView(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// DocumentView enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateDocumentView(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// DocumentView resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveDocumentView(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method CreateElement +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEELEMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateElement(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateDocumentFragment +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateDocumentFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMDocumentFragment* nativeRet; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEDOCUMENTFRAGMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + result = nativeThis->CreateDocumentFragment(&nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateTextNode +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateTextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMText* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATETEXTNODE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateTextNode(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateComment +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMComment* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATECOMMENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateComment(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateCDATASection +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateCDATASection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMCDATASection* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATECDATASECTION, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateCDATASection(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateProcessingInstruction +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateProcessingInstruction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMProcessingInstruction* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEPROCESSINGINSTRUCTION, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateProcessingInstruction(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateAttribute +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMAttr* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEATTRIBUTE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateAttribute(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateEntityReference +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateEntityReference(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMEntityReference* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEENTITYREFERENCE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateEntityReference(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagName +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNodeList* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTSBYTAGNAME, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->GetElementsByTagName(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method ImportNode +// +PR_STATIC_CALLBACK(JSBool) +DocumentImportNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNode* nativeRet; + nsCOMPtr b0; + PRBool b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_IMPORTNODE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0), + kINodeIID, + NS_ConvertASCIItoUCS2("Node"), + cx, + argv[0])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR); + } + if (!nsJSUtils::nsConvertJSValToBool(&b1, cx, argv[1])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_BOOLEAN_ERR); + } + + result = nativeThis->ImportNode(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateElementNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateElementNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEELEMENTNS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateElementNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMAttr* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_CREATEATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateAttributeNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagNameNS +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementsByTagNameNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMNodeList* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTSBYTAGNAMENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->GetElementsByTagNameNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementById +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!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_DOCUMENT_GETELEMENTBYID, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->GetElementById(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateElementWithNameSpace +// +PR_STATIC_CALLBACK(JSBool) +NSDocumentCreateElementWithNameSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kINSDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMElement* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (!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_NSDOCUMENT_CREATEELEMENTWITHNAMESPACE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->CreateElementWithNameSpace(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method CreateRange +// +PR_STATIC_CALLBACK(JSBool) +NSDocumentCreateRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocumentView *privateThis = (nsIDOMDocumentView*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kINSDocumentIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMRange* nativeRet; + // If there's no private data, this must be the prototype, so ignore + if (!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_NSDOCUMENT_CREATERANGE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + result = nativeThis->CreateRange(&nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for DocumentView +// +JSClass DocumentViewClass = { + "DocumentView", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetDocumentViewProperty, + SetDocumentViewProperty, + EnumerateDocumentView, + ResolveDocumentView, + JS_ConvertStub, + FinalizeDocumentView, + nsnull, + nsJSUtils::nsCheckAccess +}; + + +// +// DocumentView class properties +// +static JSPropertySpec DocumentViewProperties[] = +{ + {"doctype", DOCUMENT_DOCTYPE, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"implementation", DOCUMENT_IMPLEMENTATION, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"styleSheets", DOCUMENTSTYLE_STYLESHEETS, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"defaultView", DOCUMENTVIEW_DEFAULTVIEW, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"width", NSDOCUMENT_WIDTH, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"height", NSDOCUMENT_HEIGHT, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"characterSet", NSDOCUMENT_CHARACTERSET, JSPROP_ENUMERATE | JSPROP_READONLY}, + {0} +}; + + +// +// DocumentView class methods +// +static JSFunctionSpec DocumentViewMethods[] = +{ + {"createElement", DocumentCreateElement, 1}, + {"createDocumentFragment", DocumentCreateDocumentFragment, 0}, + {"createTextNode", DocumentCreateTextNode, 1}, + {"createComment", DocumentCreateComment, 1}, + {"createCDATASection", DocumentCreateCDATASection, 1}, + {"createProcessingInstruction", DocumentCreateProcessingInstruction, 2}, + {"createAttribute", DocumentCreateAttribute, 1}, + {"createEntityReference", DocumentCreateEntityReference, 1}, + {"getElementsByTagName", DocumentGetElementsByTagName, 1}, + {"importNode", DocumentImportNode, 2}, + {"createElementNS", DocumentCreateElementNS, 2}, + {"createAttributeNS", DocumentCreateAttributeNS, 2}, + {"getElementsByTagNameNS", DocumentGetElementsByTagNameNS, 2}, + {"getElementById", DocumentGetElementById, 1}, + {"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2}, + {"createRange", NSDocumentCreateRange, 0}, + {0} +}; + + +// +// DocumentView constructor +// +PR_STATIC_CALLBACK(JSBool) +DocumentView(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_FALSE; +} + + +// +// DocumentView class initialization +// +extern "C" NS_DOM nsresult NS_InitDocumentViewClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentView", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DocumentViewClass, // JSClass + DocumentView, // JSNative ctor + 0, // ctor args + DocumentViewProperties, // proto props + DocumentViewMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new DocumentView JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptDocumentView(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentView"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMDocumentView *aDocumentView; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDocumentViewClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIDocumentViewIID, (void **)&aDocumentView); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &DocumentViewClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aDocumentView); + } + else { + NS_RELEASE(aDocumentView); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/coreDOM/nsJSMediaList.cpp b/mozilla/dom/src/coreDOM/nsJSMediaList.cpp new file mode 100644 index 00000000000..2369da8d587 --- /dev/null +++ b/mozilla/dom/src/coreDOM/nsJSMediaList.cpp @@ -0,0 +1,466 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nsDOMError.h" +#include "nscore.h" +#include "nsIServiceManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptSecurityManager.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsCOMPtr.h" +#include "nsDOMPropEnums.h" +#include "nsString.h" +#include "nsIDOMMediaList.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(kIMediaListIID, NS_IDOMMEDIALIST_IID); + +// +// MediaList property ids +// +enum MediaList_slots { + MEDIALIST_MEDIATEXT = -1, + MEDIALIST_LENGTH = -2 +}; + +/***********************************************************************/ +// +// MediaList Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetMediaListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMMediaList *a = (nsIDOMMediaList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case MEDIALIST_MEDIATEXT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MEDIALIST_MEDIATEXT, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsAutoString prop; + rv = a->GetMediaText(prop); + if (NS_SUCCEEDED(rv)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + } + break; + } + case MEDIALIST_LENGTH: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MEDIALIST_LENGTH, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRUint32 prop; + rv = a->GetLength(&prop); + if (NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + } + break; + } + default: + { + nsAutoString prop; + rv = a->Item(JSVAL_TO_INT(id), prop); + if (NS_SUCCEEDED(rv)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + } + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + +/***********************************************************************/ +// +// MediaList Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetMediaListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMMediaList *a = (nsIDOMMediaList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case MEDIALIST_MEDIATEXT: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MEDIALIST_MEDIATEXT, PR_TRUE); + if (NS_SUCCEEDED(rv)) { + nsAutoString prop; + nsJSUtils::nsConvertJSValToString(prop, cx, *vp); + + rv = a->SetMediaText(prop); + + } + break; + } + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + + +// +// MediaList finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeMediaList(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// MediaList enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateMediaList(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// MediaList resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveMediaList(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method Item +// +PR_STATIC_CALLBACK(JSBool) +MediaListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMMediaList *nativeThis = (nsIDOMMediaList*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString nativeRet; + PRUint32 b0; + // 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_MEDIALIST_ITEM, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR); + } + + result = nativeThis->Item(b0, nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval); + } + + return JS_TRUE; +} + + +// +// Native method Delete +// +PR_STATIC_CALLBACK(JSBool) +MediaListDelete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMMediaList *nativeThis = (nsIDOMMediaList*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString b0; + // 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_MEDIALIST_DELETE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->Delete(b0); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +// +// Native method Append +// +PR_STATIC_CALLBACK(JSBool) +MediaListAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMMediaList *nativeThis = (nsIDOMMediaList*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString b0; + // 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_MEDIALIST_APPEND, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->Append(b0); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for MediaList +// +JSClass MediaListClass = { + "MediaList", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetMediaListProperty, + SetMediaListProperty, + EnumerateMediaList, + ResolveMediaList, + JS_ConvertStub, + FinalizeMediaList, + nsnull, + nsJSUtils::nsCheckAccess +}; + + +// +// MediaList class properties +// +static JSPropertySpec MediaListProperties[] = +{ + {"mediaText", MEDIALIST_MEDIATEXT, JSPROP_ENUMERATE}, + {"length", MEDIALIST_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY}, + {0} +}; + + +// +// MediaList class methods +// +static JSFunctionSpec MediaListMethods[] = +{ + {"item", MediaListItem, 1}, + {"delete", MediaListDelete, 1}, + {"append", MediaListAppend, 1}, + {0} +}; + + +// +// MediaList constructor +// +PR_STATIC_CALLBACK(JSBool) +MediaList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_FALSE; +} + + +// +// MediaList class initialization +// +extern "C" NS_DOM nsresult NS_InitMediaListClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "MediaList", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &MediaListClass, // JSClass + MediaList, // JSNative ctor + 0, // ctor args + MediaListProperties, // proto props + MediaListMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new MediaList JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptMediaList(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptMediaList"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMMediaList *aMediaList; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitMediaListClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIMediaListIID, (void **)&aMediaList); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &MediaListClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aMediaList); + } + else { + NS_RELEASE(aMediaList); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/coreDOM/nsJSStyleSheetList.cpp b/mozilla/dom/src/coreDOM/nsJSStyleSheetList.cpp new file mode 100644 index 00000000000..62a6a6d408c --- /dev/null +++ b/mozilla/dom/src/coreDOM/nsJSStyleSheetList.cpp @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nsDOMError.h" +#include "nscore.h" +#include "nsIServiceManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptSecurityManager.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsCOMPtr.h" +#include "nsDOMPropEnums.h" +#include "nsString.h" +#include "nsIDOMStyleSheet.h" +#include "nsIDOMStyleSheetList.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(kIStyleSheetIID, NS_IDOMSTYLESHEET_IID); +static NS_DEFINE_IID(kIStyleSheetListIID, NS_IDOMSTYLESHEETLIST_IID); + +// +// StyleSheetList property ids +// +enum StyleSheetList_slots { + STYLESHEETLIST_LENGTH = -1 +}; + +/***********************************************************************/ +// +// StyleSheetList Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetStyleSheetListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMStyleSheetList *a = (nsIDOMStyleSheetList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case STYLESHEETLIST_LENGTH: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_STYLESHEETLIST_LENGTH, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRUint32 prop; + rv = a->GetLength(&prop); + if (NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + } + break; + } + default: + { + nsIDOMStyleSheet* prop; + rv = a->Item(JSVAL_TO_INT(id), &prop); + if (NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + } + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + +/***********************************************************************/ +// +// StyleSheetList Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetStyleSheetListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMStyleSheetList *a = (nsIDOMStyleSheetList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + + +// +// StyleSheetList finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeStyleSheetList(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// StyleSheetList enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateStyleSheetList(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// StyleSheetList resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveStyleSheetList(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method Item +// +PR_STATIC_CALLBACK(JSBool) +StyleSheetListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMStyleSheetList *nativeThis = (nsIDOMStyleSheetList*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsIDOMStyleSheet* nativeRet; + PRUint32 b0; + // 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_STYLESHEETLIST_ITEM, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR); + } + + result = nativeThis->Item(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for StyleSheetList +// +JSClass StyleSheetListClass = { + "StyleSheetList", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetStyleSheetListProperty, + SetStyleSheetListProperty, + EnumerateStyleSheetList, + ResolveStyleSheetList, + JS_ConvertStub, + FinalizeStyleSheetList, + nsnull, + nsJSUtils::nsCheckAccess +}; + + +// +// StyleSheetList class properties +// +static JSPropertySpec StyleSheetListProperties[] = +{ + {"length", STYLESHEETLIST_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY}, + {0} +}; + + +// +// StyleSheetList class methods +// +static JSFunctionSpec StyleSheetListMethods[] = +{ + {"item", StyleSheetListItem, 1}, + {0} +}; + + +// +// StyleSheetList constructor +// +PR_STATIC_CALLBACK(JSBool) +StyleSheetList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_FALSE; +} + + +// +// StyleSheetList class initialization +// +extern "C" NS_DOM nsresult NS_InitStyleSheetListClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "StyleSheetList", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &StyleSheetListClass, // JSClass + StyleSheetList, // JSNative ctor + 0, // ctor args + StyleSheetListProperties, // proto props + StyleSheetListMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new StyleSheetList JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptStyleSheetList(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptStyleSheetList"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMStyleSheetList *aStyleSheetList; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitStyleSheetListClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIStyleSheetListIID, (void **)&aStyleSheetList); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &StyleSheetListClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aStyleSheetList); + } + else { + NS_RELEASE(aStyleSheetList); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/css/nsJSCSSRuleList.cpp b/mozilla/dom/src/css/nsJSCSSRuleList.cpp new file mode 100644 index 00000000000..548d338f638 --- /dev/null +++ b/mozilla/dom/src/css/nsJSCSSRuleList.cpp @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nsDOMError.h" +#include "nscore.h" +#include "nsIServiceManager.h" +#include "nsIScriptContext.h" +#include "nsIScriptSecurityManager.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsCOMPtr.h" +#include "nsDOMPropEnums.h" +#include "nsString.h" +#include "nsIDOMCSSRule.h" +#include "nsIDOMCSSRuleList.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(kICSSRuleIID, NS_IDOMCSSRULE_IID); +static NS_DEFINE_IID(kICSSRuleListIID, NS_IDOMCSSRULELIST_IID); + +// +// CSSRuleList property ids +// +enum CSSRuleList_slots { + CSSRULELIST_LENGTH = -1 +}; + +/***********************************************************************/ +// +// CSSRuleList Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetCSSRuleListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMCSSRuleList *a = (nsIDOMCSSRuleList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case CSSRULELIST_LENGTH: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_CSSRULELIST_LENGTH, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRUint32 prop; + rv = a->GetLength(&prop); + if (NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + } + break; + } + default: + { + nsIDOMCSSRule* prop; + rv = a->Item(JSVAL_TO_INT(id), &prop); + if (NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + } + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + +/***********************************************************************/ +// +// CSSRuleList Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetCSSRuleListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMCSSRuleList *a = (nsIDOMCSSRuleList*)nsJSUtils::nsGetNativeThis(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + nsresult rv = NS_OK; + if (JSVAL_IS_INT(id)) { + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp); + } + + if (NS_FAILED(rv)) + return nsJSUtils::nsReportError(cx, obj, rv); + return PR_TRUE; +} + + +// +// CSSRuleList finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeCSSRuleList(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// CSSRuleList enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateCSSRuleList(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// CSSRuleList resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveCSSRuleList(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method Item +// +PR_STATIC_CALLBACK(JSBool) +CSSRuleListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMCSSRuleList *nativeThis = (nsIDOMCSSRuleList*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsIDOMCSSRule* nativeRet; + PRUint32 b0; + // 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_CSSRULELIST_ITEM, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR); + } + + result = nativeThis->Item(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for CSSRuleList +// +JSClass CSSRuleListClass = { + "CSSRuleList", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JS_PropertyStub, + JS_PropertyStub, + GetCSSRuleListProperty, + SetCSSRuleListProperty, + EnumerateCSSRuleList, + ResolveCSSRuleList, + JS_ConvertStub, + FinalizeCSSRuleList, + nsnull, + nsJSUtils::nsCheckAccess +}; + + +// +// CSSRuleList class properties +// +static JSPropertySpec CSSRuleListProperties[] = +{ + {"length", CSSRULELIST_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY}, + {0} +}; + + +// +// CSSRuleList class methods +// +static JSFunctionSpec CSSRuleListMethods[] = +{ + {"item", CSSRuleListItem, 1}, + {0} +}; + + +// +// CSSRuleList constructor +// +PR_STATIC_CALLBACK(JSBool) +CSSRuleList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_FALSE; +} + + +// +// CSSRuleList class initialization +// +extern "C" NS_DOM nsresult NS_InitCSSRuleListClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "CSSRuleList", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &CSSRuleListClass, // JSClass + CSSRuleList, // JSNative ctor + 0, // ctor args + CSSRuleListProperties, // proto props + CSSRuleListMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new CSSRuleList JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptCSSRuleList(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptCSSRuleList"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMCSSRuleList *aCSSRuleList; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitCSSRuleListClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kICSSRuleListIID, (void **)&aCSSRuleList); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &CSSRuleListClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aCSSRuleList); + } + else { + NS_RELEASE(aCSSRuleList); + return NS_ERROR_FAILURE; + } + + return NS_OK; +}