Add new source files for crypto JS object and mods for getting it to

work as a property of the window object. r=jst@netscape.com


git-svn-id: svn://10.0.0.236/trunk@69230 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
javi%netscape.com
2000-05-11 19:17:07 +00:00
parent ced9ad03e3
commit dbf34adeda
5 changed files with 778 additions and 17 deletions

View File

@@ -57,6 +57,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h"
#include "nsIDocument.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMFocusListener.h"
@@ -66,6 +67,7 @@
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMPkcs11.h"
#include "nsIEventQueueService.h"
#include "nsIEventStateManager.h"
#include "nsIHTTPProtocolHandler.h"
@@ -88,6 +90,7 @@
#include "nsIWebBrowser.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWebShell.h"
#include "nsDOMCID.h"
#include "nsDOMError.h"
// XXX An unfortunate dependency exists here.
@@ -102,6 +105,11 @@ static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static const char *kCryptoProgID = NS_CRYPTO_PROGID;
static const char *kPkcs11ProgID = NS_PKCS11_PROGID;
//*****************************************************************************
//*** GlobalWindowImpl: Object Management
@@ -117,6 +125,8 @@ GlobalWindowImpl::GlobalWindowImpl() : mScriptObject(nsnull),
mChromeEventHandler(nsnull)
{
NS_INIT_REFCNT();
mCrypto = nsnull;
mPkcs11 = nsnull;
}
GlobalWindowImpl::~GlobalWindowImpl()
@@ -739,6 +749,30 @@ NS_IMETHODIMP GlobalWindowImpl::GetFrames(nsIDOMWindowCollection** aFrames)
return NS_OK;
}
NS_IMETHODIMP GlobalWindowImpl::GetCrypto(nsIDOMCrypto** aCrypto)
{
nsresult rv;
if (!mCrypto)
{
mCrypto = do_CreateInstance(kCryptoProgID, &rv);
}
*aCrypto = mCrypto;
return NS_OK;
}
NS_IMETHODIMP GlobalWindowImpl::GetPkcs11(nsIDOMPkcs11** aPkcs11)
{
nsresult rv;
if (!mPkcs11)
{
mPkcs11 = do_CreateInstance(kPkcs11ProgID, &rv);
}
*aPkcs11 = mPkcs11;
return NS_OK;
}
NS_IMETHODIMP GlobalWindowImpl::GetControllers(nsIControllers** aResult)
{
if(!mControllers)

View File

@@ -47,6 +47,8 @@
#include "nsPIDOMWindow.h"
#include "nsIEventListenerManager.h"
#include "nsIDOMDocument.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMPkcs11.h"
#include "nsISidebar.h"
#define DEFAULT_HOME_PAGE "www.mozilla.org"
@@ -59,7 +61,6 @@ class nsIPresContext;
class nsIDOMEvent;
class nsIScrollableView;
typedef struct nsTimeoutImpl nsTimeoutImpl;
class BarPropImpl;
@@ -227,6 +228,8 @@ protected:
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // Weak Reference
nsIDocShell* mDocShell; // Weak Reference
nsIChromeEventHandler* mChromeEventHandler; // Weak Reference
nsCOMPtr<nsIDOMCrypto> mCrypto;
nsCOMPtr<nsIDOMPkcs11> mPkcs11;
};
/*

View File

@@ -0,0 +1,306 @@
/* -*- 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 "nsIDOMCRMFObject.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(kICRMFObjectIID, NS_IDOMCRMFOBJECT_IID);
//
// CRMFObject property ids
//
enum CRMFObject_slots {
CRMFOBJECT_REQUEST = -1
};
/***********************************************************************/
//
// CRMFObject Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetCRMFObjectProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMCRMFObject *a = (nsIDOMCRMFObject*)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 CRMFOBJECT_REQUEST:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_CRMFOBJECT_REQUEST, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsAutoString prop;
rv = a->GetRequest(prop);
if (NS_SUCCEEDED(rv)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
}
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;
}
/***********************************************************************/
//
// CRMFObject Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetCRMFObjectProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMCRMFObject *a = (nsIDOMCRMFObject*)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;
}
//
// CRMFObject finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeCRMFObject(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// CRMFObject enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateCRMFObject(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// CRMFObject resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveCRMFObject(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
/***********************************************************************/
//
// class for CRMFObject
//
JSClass CRMFObjectClass = {
"CRMFObject",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetCRMFObjectProperty,
SetCRMFObjectProperty,
EnumerateCRMFObject,
ResolveCRMFObject,
JS_ConvertStub,
FinalizeCRMFObject,
nsnull,
nsJSUtils::nsCheckAccess
};
//
// CRMFObject class properties
//
static JSPropertySpec CRMFObjectProperties[] =
{
{"request", CRMFOBJECT_REQUEST, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// CRMFObject class methods
//
static JSFunctionSpec CRMFObjectMethods[] =
{
{0}
};
//
// CRMFObject constructor
//
PR_STATIC_CALLBACK(JSBool)
CRMFObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// CRMFObject class initialization
//
extern "C" NS_DOM nsresult NS_InitCRMFObjectClass(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, "CRMFObject", &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
&CRMFObjectClass, // JSClass
CRMFObject, // JSNative ctor
0, // ctor args
CRMFObjectProperties, // proto props
CRMFObjectMethods, // 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 CRMFObject JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptCRMFObject(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptCRMFObject");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMCRMFObject *aCRMFObject;
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_InitCRMFObjectClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kICRMFObjectIID, (void **)&aCRMFObject);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &CRMFObjectClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aCRMFObject);
}
else {
NS_RELEASE(aCRMFObject);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,384 @@
/* -*- 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 "nsIDOMPkcs11.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(kIPkcs11IID, NS_IDOMPKCS11_IID);
/***********************************************************************/
//
// Pkcs11 Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetPkcs11Property(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMPkcs11 *a = (nsIDOMPkcs11*)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::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;
}
/***********************************************************************/
//
// Pkcs11 Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetPkcs11Property(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMPkcs11 *a = (nsIDOMPkcs11*)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;
}
//
// Pkcs11 finalizer
//
PR_STATIC_CALLBACK(void)
FinalizePkcs11(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// Pkcs11 enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumeratePkcs11(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// Pkcs11 resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolvePkcs11(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Deletemodule
//
PR_STATIC_CALLBACK(JSBool)
Pkcs11Deletemodule(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMPkcs11 *nativeThis = (nsIDOMPkcs11*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
PRInt32 nativeRet;
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_PKCS11_DELETEMODULE, 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->Deletemodule(b0, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = INT_TO_JSVAL(nativeRet);
}
return JS_TRUE;
}
//
// Native method Addmodule
//
PR_STATIC_CALLBACK(JSBool)
Pkcs11Addmodule(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMPkcs11 *nativeThis = (nsIDOMPkcs11*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
PRInt32 b2;
PRInt32 b3;
// 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_PKCS11_ADDMODULE, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 4) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
if (!JS_ValueToInt32(cx, argv[3], (int32 *)&b3)) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
result = nativeThis->Addmodule(b0, b1, b2, b3, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = INT_TO_JSVAL(nativeRet);
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Pkcs11
//
JSClass Pkcs11Class = {
"Pkcs11",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetPkcs11Property,
SetPkcs11Property,
EnumeratePkcs11,
ResolvePkcs11,
JS_ConvertStub,
FinalizePkcs11,
nsnull,
nsJSUtils::nsCheckAccess
};
//
// Pkcs11 class properties
//
static JSPropertySpec Pkcs11Properties[] =
{
{0}
};
//
// Pkcs11 class methods
//
static JSFunctionSpec Pkcs11Methods[] =
{
{"deletemodule", Pkcs11Deletemodule, 1},
{"addmodule", Pkcs11Addmodule, 4},
{0}
};
//
// Pkcs11 constructor
//
PR_STATIC_CALLBACK(JSBool)
Pkcs11(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// Pkcs11 class initialization
//
extern "C" NS_DOM nsresult NS_InitPkcs11Class(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, "Pkcs11", &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
&Pkcs11Class, // JSClass
Pkcs11, // JSNative ctor
0, // ctor args
Pkcs11Properties, // proto props
Pkcs11Methods, // 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 Pkcs11 JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptPkcs11(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptPkcs11");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMPkcs11 *aPkcs11;
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_InitPkcs11Class(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIPkcs11IID, (void **)&aPkcs11);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &Pkcs11Class, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aPkcs11);
}
else {
NS_RELEASE(aPkcs11);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -49,7 +49,9 @@
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsISidebar.h"
#include "nsIDOMPkcs11.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMWindow.h"
#include "nsIControllers.h"
@@ -72,7 +74,9 @@ static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_IID(kISidebarIID, NS_ISIDEBAR_IID);
static NS_DEFINE_IID(kIPkcs11IID, NS_IDOMPKCS11_IID);
static NS_DEFINE_IID(kIViewCSSIID, NS_IDOMVIEWCSS_IID);
static NS_DEFINE_IID(kICryptoIID, NS_IDOMCRYPTO_IID);
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
static NS_DEFINE_IID(kIControllersIID, NS_ICONTROLLERS_IID);
@@ -99,22 +103,24 @@ enum Window_slots {
WINDOW_DIRECTORIES = -17,
WINDOW_CLOSED = -18,
WINDOW_FRAMES = -19,
WINDOW_CONTROLLERS = -20,
WINDOW_OPENER = -21,
WINDOW_STATUS = -22,
WINDOW_DEFAULTSTATUS = -23,
WINDOW_NAME = -24,
WINDOW_INNERWIDTH = -25,
WINDOW_INNERHEIGHT = -26,
WINDOW_OUTERWIDTH = -27,
WINDOW_OUTERHEIGHT = -28,
WINDOW_SCREENX = -29,
WINDOW_SCREENY = -30,
WINDOW_PAGEXOFFSET = -31,
WINDOW_PAGEYOFFSET = -32,
WINDOW_SCROLLX = -33,
WINDOW_SCROLLY = -34,
ABSTRACTVIEW_DOCUMENT = -35
WINDOW_CRYPTO = -20,
WINDOW_PKCS11 = -21,
WINDOW_CONTROLLERS = -22,
WINDOW_OPENER = -23,
WINDOW_STATUS = -24,
WINDOW_DEFAULTSTATUS = -25,
WINDOW_NAME = -26,
WINDOW_INNERWIDTH = -27,
WINDOW_INNERHEIGHT = -28,
WINDOW_OUTERWIDTH = -29,
WINDOW_OUTERHEIGHT = -30,
WINDOW_SCREENX = -31,
WINDOW_SCREENY = -32,
WINDOW_PAGEXOFFSET = -33,
WINDOW_PAGEYOFFSET = -34,
WINDOW_SCROLLX = -35,
WINDOW_SCROLLY = -36,
ABSTRACTVIEW_DOCUMENT = -37
};
/***********************************************************************/
@@ -357,6 +363,32 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case WINDOW_CRYPTO:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CRYPTO, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMCrypto* prop;
rv = a->GetCrypto(&prop);
if (NS_SUCCEEDED(rv)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
}
}
break;
}
case WINDOW_PKCS11:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_PKCS11, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMPkcs11* prop;
rv = a->GetPkcs11(&prop);
if (NS_SUCCEEDED(rv)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
}
}
break;
}
case WINDOW_OPENER:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_OPENER, PR_FALSE);
@@ -2677,6 +2709,8 @@ static JSPropertySpec WindowProperties[] =
{"directories", WINDOW_DIRECTORIES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"closed", WINDOW_CLOSED, JSPROP_ENUMERATE | JSPROP_READONLY},
{"frames", WINDOW_FRAMES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"crypto", WINDOW_CRYPTO, JSPROP_ENUMERATE | JSPROP_READONLY},
{"pkcs11", WINDOW_PKCS11, JSPROP_ENUMERATE | JSPROP_READONLY},
{"controllers", WINDOW_CONTROLLERS, JSPROP_ENUMERATE, WindowcontrollersGetter, WindowcontrollersSetter},
{"opener", WINDOW_OPENER, JSPROP_ENUMERATE},
{"status", WINDOW_STATUS, JSPROP_ENUMERATE},