From 2e8fd2697683f290b3036045bf785294ecb5fcce Mon Sep 17 00:00:00 2001 From: "ssu%netscape.com" Date: Thu, 13 May 1999 22:59:51 +0000 Subject: [PATCH] Added javascript install.WinReg object code for Windows platform only git-svn-id: svn://10.0.0.236/trunk@31491 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpinstall/src/makefile.win | 4 + mozilla/xpinstall/src/nsInstall.cpp | 51 ++++++++++- mozilla/xpinstall/src/nsInstall.h | 15 +++- mozilla/xpinstall/src/nsJSInstall.cpp | 118 +++++++++++++++++++++++--- 4 files changed, 171 insertions(+), 17 deletions(-) diff --git a/mozilla/xpinstall/src/makefile.win b/mozilla/xpinstall/src/makefile.win index ec10c9baf17..145d22f39b1 100644 --- a/mozilla/xpinstall/src/makefile.win +++ b/mozilla/xpinstall/src/makefile.win @@ -89,6 +89,10 @@ OBJS = \ .\$(OBJDIR)\nsInstallUninstall.obj \ .\$(OBJDIR)\nsInstallResources.obj \ .\$(OBJDIR)\ScheduledTasks.obj \ + .\$(OBJDIR)\nsWinReg.obj \ + .\$(OBJDIR)\nsJSWinReg.obj \ + .\$(OBJDIR)\nsWinRegItem.obj \ + .\$(OBJDIR)\nsWinRegValue.obj \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index cd3a0f0d9ae..625fe387eb7 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -54,6 +54,10 @@ #include "nsInstallPatch.h" #include "nsInstallUninstall.h" +#ifdef XP_WIN +#include "nsWinReg.h" +#endif + #ifdef XP_PC #define FILESEP "\\" #elif defined(XP_MAC) @@ -260,6 +264,30 @@ nsInstall::SetScriptObject(void *aScriptObject) return NS_OK; } +nsInstall::SaveWinRegPrototype(void *aScriptObject) +{ + mWinRegObject = (JSObject*) aScriptObject; + return NS_OK; +} + +nsInstall::SaveWinProfilePrototype(void *aScriptObject) +{ + mWinProfileObject = (JSObject*) aScriptObject; + return NS_OK; +} + +JSObject* +nsInstall::RetrieveWinRegPrototype() +{ + return mWinRegObject; +} + +JSObject* +nsInstall::RetrieveWinProfilePrototype() +{ + return mWinProfileObject; +} + PRInt32 nsInstall::GetUserPackageName(nsString& aUserPackageName) { @@ -2313,12 +2341,33 @@ nsInstall::GetLastError(PRInt32* aReturn) PRInt32 nsInstall::GetWinProfile(const nsString& aFolder, const nsString& aFile, PRInt32* aReturn) { +#ifdef XP_WIN +#endif /* XP_WIN */ + return NS_OK; } PRInt32 -nsInstall::GetWinRegistry(PRInt32* aReturn) +nsInstall::GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn) { +#ifdef XP_WIN + JSObject* winRegObject; + nsWinReg* nativeWinRegObject = new nsWinReg(this); + JSObject* winRegPrototype = this->RetrieveWinRegPrototype(); + + winRegObject = JS_NewObject(jscontext, WinRegClass, winRegPrototype, NULL); + if(winRegObject == NULL) + { + return PR_FALSE; + } + + JS_SetPrivate(jscontext, winRegObject, nativeWinRegObject); + + *aReturn = OBJECT_TO_JSVAL(winRegObject); +#else + *aReturn = JSVAL_NULL; +#endif /* XP_WIN */ + return NS_OK; } diff --git a/mozilla/xpinstall/src/nsInstall.h b/mozilla/xpinstall/src/nsInstall.h index a0a9664036c..6f5287ddc1f 100644 --- a/mozilla/xpinstall/src/nsInstall.h +++ b/mozilla/xpinstall/src/nsInstall.h @@ -91,6 +91,8 @@ class nsInstallInfo class nsInstall { + friend class nsWinReg; + public: enum @@ -139,7 +141,13 @@ class nsInstall nsInstall(); ~nsInstall(); - PRInt32 SetScriptObject(void* aScriptObject); + PRInt32 SetScriptObject(void* aScriptObject); + + PRInt32 SaveWinRegPrototype(void* aScriptObject); + PRInt32 SaveWinProfilePrototype(void* aScriptObject); + + JSObject* RetrieveWinRegPrototype(void); + JSObject* RetrieveWinProfilePrototype(void); PRInt32 GetUserPackageName(nsString& aUserPackageName); PRInt32 GetRegPackageName(nsString& aRegPackageName); @@ -170,7 +178,7 @@ class nsInstall PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder); PRInt32 GetLastError(PRInt32* aReturn); PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, PRInt32* aReturn); - PRInt32 GetWinRegistry(PRInt32* aReturn); + PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn); PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); @@ -198,6 +206,9 @@ class nsInstall private: JSObject* mScriptObject; + JSObject* mWinRegObject; + JSObject* mWinProfileObject; + nsString mJarFileLocation; void* mJarFileData; diff --git a/mozilla/xpinstall/src/nsJSInstall.cpp b/mozilla/xpinstall/src/nsJSInstall.cpp index aee2077b0ce..1e9ee5f65eb 100644 --- a/mozilla/xpinstall/src/nsJSInstall.cpp +++ b/mozilla/xpinstall/src/nsJSInstall.cpp @@ -26,6 +26,13 @@ #include "nsIDOMInstallVersion.h" +#ifdef XP_WIN +#include "nsWinReg.h" +#include "nsJSWinReg.h" + +extern JSClass WinRegClass; +#endif + // // Install property ids // @@ -39,6 +46,23 @@ enum Install_slots INSTALL_ARGUMENTS = -6 }; +/***********************************************************************/ +// +// class for WinProfile +// +// JSClass WinProfileClass = { +// "WinProfile", +// JSCLASS_HAS_PRIVATE, +// JS_PropertyStub, +// JS_PropertyStub, +// JS_PropertyStub, +// JS_PropertyStub, +// JS_EnumerateStub, +// JS_ResolveStub, +// JS_ConvertStub, +// WinProfileCleanup +//}; + /***********************************************************************/ // // Install Properties Getter @@ -148,6 +172,12 @@ static void PR_CALLBACK FinalizeInstall(JSContext *cx, JSObject *obj) delete nativeThis; } +// static void PR_CALLBACK WinProfileCleanup(JSContext *cx, JSObject *obj) +// { +// nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj); +// delete nativeThis; +// } + void nsCvrtJSValToStr(nsString& aString, JSContext* aContext, jsval aValue) @@ -1026,31 +1056,30 @@ InstallGetWinRegistry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); JSBool rBool = JS_FALSE; - PRInt32 nativeRet; *rval = JSVAL_NULL; +#ifdef XP_WIN // If there's no private data, this must be the prototype, so ignore - if (nsnull == nativeThis) { + if(nsnull == nativeThis) + { return JS_TRUE; } if(argc >= 0) { // public int GetWinRegistry (void); - - if(NS_OK != nativeThis->GetWinRegistry(&nativeRet)) + if(NS_OK != nativeThis->GetWinRegistry(cx, &WinRegClass, rval)) { return JS_FALSE; } - - *rval = INT_TO_JSVAL(nativeRet); } else { JS_ReportError(cx, "Function GetWinRegistry requires 0 parameters"); return JS_FALSE; } +#endif return JS_TRUE; } @@ -1368,9 +1397,6 @@ InstallUninstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r } - - - /***********************************************************************/ // // class for Install @@ -1388,7 +1414,6 @@ JSClass InstallClass = { FinalizeInstall }; - // // Install class properties // @@ -1439,7 +1464,6 @@ static JSConstDoubleSpec install_constants[] = {0} }; - // // Install class methods // @@ -1468,6 +1492,20 @@ static JSFunctionSpec InstallMethods[] = }; +// +// WinProfile class methods +// +// static JSFunctionSpec WinProfileMethods[] = +// { +// {"writeString", WinProfileWriteString, 3}, +// {"getString", WinProfileGetString, 2}, +// {"getFilename", WinProfileGetFilename, 0}, +// {"install", WinProfileInstall, 0}, +// {"finalWriteString", WinProfileFinalWriteString, 3}, +// {0} +// }; + + // // Install constructor // @@ -1486,6 +1524,8 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); JSObject *global = JS_GetGlobalObject(jscontext); JSObject *installObject = nsnull; + JSObject *winRegPrototype = nsnull; +// JSObject *winProfilePrototype = nsnull; nsInstall *nativeInstallObject; installObject = JS_InitClass( jscontext, // context @@ -1499,6 +1539,17 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co InstallProperties, // ctor props (static) InstallMethods); // ctor funcs (static) +// winProfilePrototype = JS_InitClass( jscontext, // context +// global, // global object +// nsnull, // parent proto +// &WinProfileClass, // JSClass +// nsnull, // JSNative ctor +// 0, // ctor args +// nsnull, // proto props +// nsnull, // proto funcs +// nsnull, // ctor props (static) +// WinProfileMethods); // ctor funcs (static) + if (nsnull == installObject) { return NS_ERROR_FAILURE; @@ -1507,7 +1558,6 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co if ( PR_FALSE == JS_DefineConstDoubles(jscontext, installObject, install_constants) ) return NS_ERROR_FAILURE; - nativeInstallObject = new nsInstall(); nativeInstallObject->SetJarFileLocation(jarfile); @@ -1516,6 +1566,20 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co JS_SetPrivate(jscontext, installObject, nativeInstallObject); nativeInstallObject->SetScriptObject(installObject); +#ifdef XP_WIN + if(NS_OK != InitWinRegPrototype(jscontext, global, &winRegPrototype)) + { + return NS_ERROR_FAILURE; + } + nativeInstallObject->SaveWinRegPrototype(winRegPrototype); + +// if(NS_OK != InitWinProfileObject(jscontext, global, winRegPrototype) +// { +// return NS_ERROR_FAILURE; +// } +// nativeInstallObject->SaveWinProfilePrototype(winProfilePrototype); +#endif + return NS_OK; } @@ -1524,7 +1588,9 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* jarfile, const char* args) { - JSObject *installObject = nsnull; + JSObject *installObject = nsnull; + JSObject *winRegPrototype = nsnull; +// JSObject *winProfilePrototype = nsnull; nsInstall *nativeInstallObject; installObject = JS_InitClass( jscontext, // context @@ -1538,6 +1604,17 @@ PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* InstallProperties, // ctor props (static) InstallMethods); // ctor funcs (static) +// winProfilePrototype = JS_InitClass( jscontext, // context +// global, // global object +// nsnull, // parent proto +// &WinProfileClass, // JSClass +// nsnull, // JSNative ctor +// 0, // ctor args +// nsnull, // proto props +// nsnull, // proto funcs +// nsnull, // ctor props (static) +// WinProfileMethods); // ctor funcs (static) + if (nsnull == installObject) { return NS_ERROR_FAILURE; @@ -1546,7 +1623,6 @@ PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* if ( PR_FALSE == JS_DefineConstDoubles(jscontext, installObject, install_constants) ) return NS_ERROR_FAILURE; - nativeInstallObject = new nsInstall(); nativeInstallObject->SetJarFileLocation(jarfile); @@ -1555,5 +1631,19 @@ PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* JS_SetPrivate(jscontext, installObject, nativeInstallObject); nativeInstallObject->SetScriptObject(installObject); +#ifdef XP_WIN + if(NS_OK != InitWinRegPrototype(jscontext, global, &winRegPrototype)) + { + return NS_ERROR_FAILURE; + } + nativeInstallObject->SaveWinRegPrototype(winRegPrototype); + +// if(NS_OK != InitWinProfileObject(jscontext, global, winRegPrototype) +// { +// return NS_ERROR_FAILURE; +// } +// nativeInstallObject->SaveWinProfilePrototype(winProfilePrototype); +#endif + return NS_OK; }