Back to index

lightning-sunbird  0.9+nobinonly
nsJSInstall.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Jens Bannmann <jens.b@web.de>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "jsapi.h"
00040 #include "nsJSFile.h"
00041 #include "nscore.h"
00042 #include "nsIScriptContext.h"
00043 
00044 #include "nsBuildID.h"
00045 #include "nsString.h"
00046 #include "nsReadableUtils.h"
00047 #include "nsInstall.h"
00048 #include "nsInstallFile.h"
00049 #include "nsInstallTrigger.h"
00050 #include "nsIPromptService.h"
00051 
00052 #include "nsIDOMInstallVersion.h"
00053 
00054 #include <stdio.h>
00055 
00056 #ifdef _WINDOWS
00057 #include "nsJSWinReg.h"
00058 #include "nsJSWinProfile.h"
00059 
00060 extern JSClass WinRegClass;
00061 extern JSClass WinProfileClass;
00062 #endif
00063 
00064 #include "nsJSFileSpecObj.h"
00065 extern JSClass FileSpecObjectClass;
00066 
00067 extern JSClass FileOpClass;
00068 
00069 PR_STATIC_CALLBACK(JSBool)
00070 GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00071 
00072 PR_STATIC_CALLBACK(JSBool)
00073 SetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00074 
00075 PR_STATIC_CALLBACK(void)
00076 FinalizeInstall(JSContext *cx, JSObject *obj);
00077 
00078 /***********************************************************************/
00079 //
00080 // class for Install
00081 //
00082 JSClass InstallClass = {
00083   "Install",
00084   JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
00085   JS_PropertyStub,
00086   JS_PropertyStub,
00087   GetInstallProperty,
00088   SetInstallProperty,
00089   JS_EnumerateStub,
00090   JS_ResolveStub,
00091   JS_ConvertStub,
00092   FinalizeInstall
00093 };
00094 
00095 //
00096 // Install property ids
00097 //
00098 enum Install_slots
00099 {
00100   INSTALL_PLATFORM        = -1,
00101   INSTALL_JARFILE         = -2,
00102   INSTALL_ARCHIVE         = -3,
00103   INSTALL_ARGUMENTS       = -4,
00104   INSTALL_URL             = -5,
00105   INSTALL_FLAGS           = -6,
00106   INSTALL_FINALSTATUS     = -7,
00107   INSTALL_INSTALL         = -8,
00108   INSTALL_INSTALLED_FILES = -9
00109 };
00110 
00111 // prototype for fileOp object
00112 JSObject *gFileOpProto = nsnull;
00113 
00114 // prototype for filespec objects
00115 JSObject *gFileSpecProto = nsnull;
00116 
00117 
00118 JSObject *gFileOpObject = nsnull;
00119 /***********************************************************************/
00120 //
00121 // Install Properties Getter
00122 //
00123 PR_STATIC_CALLBACK(JSBool)
00124 GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
00125 {
00126   nsInstall *a = (nsInstall*)JS_GetPrivate(cx, obj);
00127 
00128   // If there's no private data, this must be the prototype, so ignore
00129   if (nsnull == a) {
00130     return JS_TRUE;
00131   }
00132 
00133   if (JSVAL_IS_INT(id))
00134   {
00135     switch(JSVAL_TO_INT(id)) {
00136       case INSTALL_PLATFORM:
00137       {
00138         nsCAutoString prop;
00139         a->GetInstallPlatform(prop);
00140         *vp = STRING_TO_JSVAL( JS_NewStringCopyZ(cx, prop.get()) );
00141         break;
00142       }
00143 
00144       case INSTALL_ARCHIVE:
00145       case INSTALL_JARFILE:
00146       {
00147         nsInstallFolder* folder = new nsInstallFolder();
00148         if ( folder )
00149         {
00150           folder->Init(a->GetJarFileLocation(),EmptyString());
00151           JSObject* fileSpecObject =
00152               JS_NewObject(cx, &FileSpecObjectClass, gFileSpecProto, NULL);
00153 
00154           if (fileSpecObject)
00155           {
00156             JS_SetPrivate(cx, fileSpecObject, folder);
00157             *vp = OBJECT_TO_JSVAL(fileSpecObject);
00158           }
00159           else
00160               delete folder;
00161         }
00162         break;
00163       }
00164 
00165       case INSTALL_ARGUMENTS:
00166       {
00167         nsAutoString prop;
00168 
00169         a->GetInstallArguments(prop);
00170         *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*, prop.get()), prop.Length()) );
00171 
00172         break;
00173       }
00174 
00175       case INSTALL_URL:
00176       {
00177         nsString prop;
00178 
00179         a->GetInstallURL(prop);
00180         *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*, prop.get()), prop.Length()) );
00181 
00182         break;
00183       }
00184 
00185       case INSTALL_FLAGS:
00186           *vp = INT_TO_JSVAL( a->GetInstallFlags() );
00187           break;
00188 
00189       case INSTALL_FINALSTATUS:
00190           *vp = INT_TO_JSVAL( a->GetFinalStatus() );
00191           break;
00192 
00193       case INSTALL_INSTALL:
00194           *vp = OBJECT_TO_JSVAL(obj);
00195           break;
00196 
00197       case INSTALL_INSTALLED_FILES:
00198           *vp = BOOLEAN_TO_JSVAL( a->InInstallTransaction() );
00199           break;
00200 
00201       default:
00202         return JS_TRUE;
00203     }
00204   }
00205   else {
00206     return JS_TRUE;
00207   }
00208 
00209   return PR_TRUE;
00210 }
00211 
00212 /***********************************************************************/
00213 //
00214 // Install Properties Setter
00215 //
00216 PR_STATIC_CALLBACK(JSBool)
00217 SetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
00218 {
00219   nsInstall *a = (nsInstall*)JS_GetPrivate(cx, obj);
00220 
00221   // If there's no private data, this must be the prototype, so ignore
00222   if (nsnull == a) {
00223     return JS_TRUE;
00224   }
00225 
00226   if (JSVAL_IS_INT(id)) {
00227     switch(JSVAL_TO_INT(id)) {
00228       case 0:
00229       default:
00230           return JS_TRUE;
00231     }
00232   }
00233   else {
00234     return JS_TRUE;
00235   }
00236 
00237   return PR_TRUE;
00238 }
00239 
00240 
00241 static void PR_CALLBACK FinalizeInstall(JSContext *cx, JSObject *obj)
00242 {
00243     nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj);
00244     delete nativeThis;
00245 }
00246 
00247 /***********************************************************************/
00248 /*                        JS Utilities                                 */
00249 /***********************************************************************/
00250 void ConvertJSValToStr(nsString&  aString,
00251                       JSContext* aContext,
00252                       jsval      aValue)
00253 {
00254   JSString *jsstring;
00255 
00256   if ( !JSVAL_IS_NULL(aValue) &&
00257        (jsstring = JS_ValueToString(aContext, aValue)) != nsnull)
00258   {
00259     aString.Assign(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(jsstring)));
00260   }
00261   else
00262   {
00263     aString.Truncate();
00264   }
00265 }
00266 
00267 void ConvertStrToJSVal(const nsString& aProp,
00268                       JSContext* aContext,
00269                       jsval* aReturn)
00270 {
00271   JSString *jsstring = JS_NewUCStringCopyN(aContext, NS_REINTERPRET_CAST(const jschar*, aProp.get()), aProp.Length());
00272   // set the return value
00273   *aReturn = STRING_TO_JSVAL(jsstring);
00274 }
00275 
00276 PRBool ConvertJSValToBool(PRBool* aProp,
00277                          JSContext* aContext,
00278                          jsval aValue)
00279 {
00280   JSBool temp;
00281   if(JSVAL_IS_BOOLEAN(aValue) && JS_ValueToBoolean(aContext, aValue, &temp))
00282   {
00283     *aProp = (PRBool)temp;
00284   }
00285   else
00286   {
00287     JS_ReportError(aContext, "Parameter must be a boolean");
00288     return JS_FALSE;
00289   }
00290 
00291   return JS_TRUE;
00292 }
00293 
00294 PRBool ConvertJSValToObj(nsISupports** aSupports,
00295                         REFNSIID aIID,
00296                         JSClass* aClass,
00297                         JSContext* aContext,
00298                         jsval aValue)
00299 {
00300   if (JSVAL_IS_NULL(aValue)) {
00301     *aSupports = nsnull;
00302     return JS_TRUE;
00303   }
00304   if (!JSVAL_IS_OBJECT(aValue)) {
00305     JS_ReportError(aContext, "Parameter must be an object");
00306     return JS_FALSE;
00307   }
00308   JSObject* jsobj = JSVAL_TO_OBJECT(aValue);
00309   JSClass* jsclass = JS_GetClass(aContext, jsobj);
00310   if (!jsclass ||
00311       !(jsclass->flags & JSCLASS_HAS_PRIVATE) ||
00312       !(jsclass->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS)) {
00313     JS_ReportError(aContext,
00314                    "Parameter isn't an object that implements nsISupports");
00315     return JS_FALSE;
00316   }
00317   if (!JS_InstanceOf(aContext,
00318                      jsobj,
00319                      aClass,
00320                      nsnull))
00321   {
00322     char buf[128];
00323     sprintf(buf, "Parameter isn't an instance of type %s", aClass->name);
00324     JS_ReportError(aContext, buf);
00325     return JS_FALSE;
00326   }
00327   nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, jsobj);
00328   if (!supports) {
00329     NS_ERROR("This should not happen.");
00330     JS_ReportError(aContext,
00331                    "JSObject has JSCLASS_PRIVATE_IS_NSISUPPORTS flag but has a null private slot, please file a bug.");
00332     return JS_FALSE;
00333   }
00334   if (NS_FAILED(supports->QueryInterface(aIID, (void **)aSupports))) {
00335     char buf[128];
00336     sprintf(buf, "Parameter must be of type %s", aClass->name);
00337     JS_ReportError(aContext, buf);
00338     return JS_FALSE;
00339   }
00340 
00341   return JS_TRUE;
00342 }
00343 
00344 
00345 void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval argument)
00346 {
00347     versionString.SetLength(0);
00348 
00349     if( JSVAL_IS_OBJECT(argument) )
00350     {
00351         if(!JSVAL_IS_NULL(argument))
00352         {
00353             JSObject* jsobj   = JSVAL_TO_OBJECT(argument);
00354             JSClass*  jsclass = JS_GetClass(cx, jsobj);
00355 
00356             if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE))
00357             {
00358                 nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj);
00359                 version->ToString(versionString);
00360             }
00361         }
00362     }
00363     else
00364     {
00365         ConvertJSValToStr(versionString, cx, argument);
00366     }
00367 }
00368 /***********************************************************************/
00369 /***********************************************************************/
00370 
00371 //
00372 // Native method AbortInstall
00373 //
00374 PR_STATIC_CALLBACK(JSBool)
00375 InstallAbortInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00376 {
00377   nsInstall *nativeThis =
00378     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00379 
00380   int32   b0;
00381 
00382   *rval = JSVAL_VOID;
00383 
00384   // If there's no private data, this must be the prototype, so ignore
00385   if (nsnull == nativeThis) {
00386     return JS_TRUE;
00387   }
00388 
00389   if(argc >= 1)
00390   {
00391     //  public int AbortInstall(Number aErrorNumber);
00392     if(JS_ValueToInt32(cx, argv[0], &b0))
00393     {
00394       nativeThis->AbortInstall(b0);
00395     }
00396     else
00397     {
00398       JS_ReportError(cx, "Parameter must be a number");
00399     }
00400   }
00401   else if(argc == 0)
00402   {
00403     //  public int AbortInstall(void);
00404     nativeThis->AbortInstall(nsInstall::INSTALL_CANCELLED);
00405   }
00406 
00407   return JS_TRUE;
00408 }
00409 
00410 
00411 //
00412 // Native method AddDirectory
00413 //
00414 PR_STATIC_CALLBACK(JSBool)
00415 InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00416 {
00417   nsInstall *nativeThis =
00418     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00419 
00420   PRInt32 nativeRet;
00421   nsAutoString b0;
00422   nsAutoString b1;
00423   nsAutoString b2;
00424   nsAutoString b3;
00425   nsAutoString b4;
00426   JSObject *jsObj;
00427   nsInstallFolder *folder;
00428   PRInt32 flags;
00429 
00430   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00431 
00432   // If there's no private data, this must be the prototype, so ignore
00433   if (nsnull == nativeThis) {
00434     return JS_TRUE;
00435   }
00436 
00437   if (argc == 1)
00438   {
00439     // public int AddDirectory (String jarSourcePath)
00440 
00441     ConvertJSValToStr(b0, cx, argv[0]);
00442 
00443     if(NS_OK == nativeThis->AddDirectory(b0, &nativeRet))
00444     {
00445       *rval = INT_TO_JSVAL(nativeRet);
00446     }
00447   }
00448   else if (argc == 4)
00449   {
00450     //  public int AddDirectory ( String registryName,
00451     //                            String jarSourcePath,
00452     //                            Object localDirSpec,
00453     //                            String relativeLocalPath);
00454 
00455     ConvertJSValToStr(b0, cx, argv[0]);
00456     ConvertJSValToStr(b1, cx, argv[1]);
00457     ConvertJSValToStr(b3, cx, argv[3]);
00458     if (argv[2] == JSVAL_NULL || !JSVAL_IS_OBJECT(argv[2])) //argv[2] MUST be a jsval
00459     {
00460       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00461       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00462       return JS_TRUE;
00463     }
00464 
00465     jsObj = JSVAL_TO_OBJECT(argv[2]);
00466     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00467     {
00468       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00469       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00470       return JS_TRUE;
00471     }
00472 
00473     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00474 
00475     if(NS_OK == nativeThis->AddDirectory(b0, b1, folder, b3, &nativeRet))
00476     {
00477       *rval = INT_TO_JSVAL(nativeRet);
00478     }
00479   }
00480   else if (argc == 5)
00481   {
00482     //  public int AddDirectory ( String registryName,
00483     //                            String version,  --OR-- VersionInfo version
00484     //                            String jarSourcePath,
00485     //                            Object localDirSpec,
00486     //                            String relativeLocalPath);
00487 
00488     ConvertJSValToStr(b0, cx, argv[0]);
00489     ConvertJSvalToVersionString(b1, cx, argv[1]);
00490     ConvertJSValToStr(b2, cx, argv[2]);
00491     ConvertJSValToStr(b4, cx, argv[4]);
00492 
00493     if ((argv[3] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[3])) //argv[3] MUST be a jsval
00494     {
00495       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00496       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00497       return JS_TRUE;
00498     }
00499 
00500     jsObj = JSVAL_TO_OBJECT(argv[3]);
00501     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00502     {
00503       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00504       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00505       return JS_TRUE;
00506     }
00507 
00508     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00509 
00510     if(NS_OK == nativeThis->AddDirectory(b0, b1, b2, folder, b4, &nativeRet))
00511     {
00512       *rval = INT_TO_JSVAL(nativeRet);
00513     }
00514   }
00515   else if (argc >= 6)
00516   {
00517      //   public int AddDirectory (  String registryName,
00518      //                              String version,        --OR--     VersionInfo version,
00519      //                              String jarSourcePath,
00520      //                              Object localDirSpec,
00521      //                              String relativeLocalPath,
00522      //                              Int    flags);
00523 
00524     ConvertJSValToStr(b0, cx, argv[0]);
00525     ConvertJSvalToVersionString(b1, cx, argv[1]);
00526     ConvertJSValToStr(b2, cx, argv[2]);
00527     ConvertJSValToStr(b4, cx, argv[4]);
00528 
00529     if ((argv[3] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[3])) //argv[3] MUST be a jsval
00530     {
00531       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00532       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00533       return JS_TRUE;
00534     }
00535 
00536     jsObj = JSVAL_TO_OBJECT(argv[3]);
00537     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00538     {
00539       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00540       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00541       return JS_TRUE;
00542     }
00543 
00544     if(JSVAL_IS_INT(argv[5]))
00545       flags = JSVAL_TO_INT(argv[5]);
00546     else
00547       flags = 0;
00548 
00549     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00550 
00551     if(NS_OK == nativeThis->AddDirectory(b0, b1, b2, folder, b4, flags, &nativeRet))
00552     {
00553       *rval = INT_TO_JSVAL(nativeRet);
00554     }
00555   }
00556   else
00557   {
00558     JS_ReportError(cx, "Install.AddDirectory() parameters error");
00559   }
00560 
00561   return JS_TRUE;
00562 }
00563 
00564 
00565 //
00566 // Native method AddSubcomponent
00567 //
00568 PR_STATIC_CALLBACK(JSBool)
00569 InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00570 {
00571   nsInstall *nativeThis =
00572     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00573 
00574   PRInt32 nativeRet;
00575   nsAutoString b0;
00576   nsAutoString b1;
00577   nsAutoString b2;
00578   nsAutoString b3;
00579   nsAutoString b4;
00580   JSObject* jsObj;
00581   nsInstallFolder* folder;
00582   PRInt32 flags = 0;
00583   nsresult rv;
00584 
00585   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00586 
00587   // If there's no private data, this must be the prototype, so ignore
00588   if (nsnull == nativeThis) {
00589     return JS_TRUE;
00590   }
00591 
00592   if(argc >= 6)
00593   {
00594     //  public int AddSubcomponent ( String registryName,
00595     //                               String version,        --OR--     VersionInfo version,
00596     //                               String jarSourcePath,
00597     //                               Object localDirSpec,
00598     //                               String relativeLocalPath,
00599     //                               Int    flags);
00600 
00601     ConvertJSValToStr(b0, cx, argv[0]);
00602     ConvertJSvalToVersionString(b1, cx, argv[1]);
00603     ConvertJSValToStr(b2, cx, argv[2]);
00604     ConvertJSValToStr(b4, cx, argv[4]);
00605 
00606     if ((argv[3] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[3])) //argv[3] MUST be a jsval
00607     {
00608       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00609       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00610       return JS_TRUE;
00611     }
00612 
00613     jsObj = JSVAL_TO_OBJECT(argv[3]);
00614     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00615     {
00616       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00617       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00618       return JS_TRUE;
00619     }
00620 
00621     if(JSVAL_IS_INT(argv[5]))
00622       flags = JSVAL_TO_INT(argv[5]);
00623     else
00624       flags = 0;
00625 
00626     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00627 
00628     jsrefcount saveDepth;
00629     saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
00630     rv= nativeThis->AddSubcomponent(b0, b1, b2, folder, b4, flags, &nativeRet);
00631     JS_ResumeRequest(cx, saveDepth);
00632 
00633     if (NS_SUCCEEDED(rv))
00634       *rval = INT_TO_JSVAL(nativeRet);
00635   }
00636   else if(argc >= 5)
00637   {
00638     //  public int AddSubcomponent ( String registryName,
00639     //                               String version,  --OR-- VersionInfo version
00640     //                               String jarSourcePath,
00641     //                               Object localDirSpec,
00642     //                               String relativeLocalPath);
00643 
00644     ConvertJSValToStr(b0, cx, argv[0]);
00645     ConvertJSvalToVersionString(b1, cx, argv[1]);
00646     ConvertJSValToStr(b2, cx, argv[2]);
00647     ConvertJSValToStr(b4, cx, argv[4]);
00648 
00649     if ((argv[3] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[3])) //argv[3] MUST be a jsval
00650     {
00651       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00652       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00653       return JS_TRUE;
00654     }
00655 
00656     jsObj = JSVAL_TO_OBJECT(argv[3]);
00657 
00658     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00659     {
00660       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00661       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00662       return JS_TRUE;
00663     }
00664 
00665     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00666 
00667     jsrefcount saveDepth;
00668     saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
00669     rv = nativeThis->AddSubcomponent(b0, b1, b2, folder, b4, &nativeRet);
00670     JS_ResumeRequest(cx, saveDepth);
00671 
00672     if (NS_SUCCEEDED(rv))
00673       *rval = INT_TO_JSVAL(nativeRet);
00674   }
00675   else if(argc >= 4)
00676   {
00677     //  public int AddSubcomponent ( String registryName,
00678     //                               String jarSourcePath,
00679     //                               Object localDirSpec,
00680     //                               String relativeLocalPath);
00681 
00682     ConvertJSValToStr(b0, cx, argv[0]);
00683     ConvertJSValToStr(b1, cx, argv[1]);
00684     ConvertJSValToStr(b3, cx, argv[3]);
00685 
00686     if ((argv[2] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[2])) //argv[2] MUST be a jsval
00687     {
00688       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00689       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00690       return JS_TRUE;
00691     }
00692 
00693     jsObj = JSVAL_TO_OBJECT(argv[2]);
00694     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00695     {
00696       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
00697       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
00698       return JS_TRUE;
00699     }
00700 
00701     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
00702 
00703     if(NS_OK == nativeThis->AddSubcomponent(b0, b1, folder, b3, &nativeRet))
00704     {
00705       *rval = INT_TO_JSVAL(nativeRet);
00706     }
00707   }
00708   else if(argc >= 1)
00709   {
00710     //  public int AddSubcomponent ( String jarSourcePath);
00711 
00712     ConvertJSValToStr(b0, cx, argv[0]);
00713 
00714     if(NS_OK == nativeThis->AddSubcomponent(b0, &nativeRet))
00715     {
00716       *rval = INT_TO_JSVAL(nativeRet);
00717     }
00718   }
00719   else
00720   {
00721     JS_ReportError(cx, "Install.addFile parameter error");
00722   }
00723 
00724   return JS_TRUE;
00725 }
00726 
00727 
00728 //
00729 // Native method DeleteComponent
00730 //
00731 PR_STATIC_CALLBACK(JSBool)
00732 InstallDeleteComponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00733 {
00734   // this function was once documented but never supported. Return an error,
00735   // but don't remove which would kill scripts that reference this.
00736   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00737   return JS_TRUE;
00738 }
00739 
00740 //
00741 // Native method Execute
00742 //
00743 PR_STATIC_CALLBACK(JSBool)
00744 InstallExecute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00745 {
00746   nsInstall *nativeThis =
00747     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00748 
00749   PRInt32 nativeRet;
00750   nsAutoString b0;
00751   nsAutoString b1;
00752   PRBool       blocking = PR_FALSE;
00753 
00754   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00755 
00756   // If there's no private data, this must be the prototype, so ignore
00757   if (nsnull == nativeThis) {
00758     return JS_TRUE;
00759   }
00760 
00761   if(argc >= 3)
00762   {
00763     //  public int Execute ( String jarSourcePath,
00764     //                       String args,
00765     //                       Bool   blocking);
00766 
00767     ConvertJSValToStr(b1, cx, argv[1]);
00768     ConvertJSValToBool(&blocking, cx,argv[2]);
00769   }
00770   else if(argc >= 2)
00771   {
00772     if(JSVAL_IS_BOOLEAN(argv[1]))
00773     {
00774       //  public int Execute ( String jarSourcePath,
00775       //                       Bool   blocking);
00776       ConvertJSValToBool(&blocking, cx, argv[1]);
00777     }
00778     else
00779     {
00780       //  public int Execute ( String jarSourcePath,
00781       //                       String args);
00782       ConvertJSValToStr(b1, cx, argv[1]);
00783     }
00784   }
00785 
00786   if(argc >= 1)
00787   {
00788     //  public int Execute ( String jarSourcePath);
00789     ConvertJSValToStr(b0, cx, argv[0]);
00790 
00791     jsrefcount saveDepth;
00792     saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
00793     nativeThis->Execute(b0, b1, blocking, &nativeRet);
00794     JS_ResumeRequest(cx, saveDepth);
00795 
00796     *rval = INT_TO_JSVAL(nativeRet);
00797   }
00798   else
00799   {
00800     JS_ReportWarning(cx, "Function Execute requires 1 parameter");
00801   }
00802 
00803   return JS_TRUE;
00804 }
00805 
00806 
00807 //
00808 // Native method FinalizeInstall
00809 //
00810 PR_STATIC_CALLBACK(JSBool)
00811 InstallFinalizeInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00812 {
00813   nsInstall *nativeThis =
00814     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00815 
00816   PRInt32 nativeRet;
00817 
00818   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00819 
00820   // If there's no private data, this must be the prototype, so ignore
00821   if (nsnull == nativeThis) {
00822     return JS_TRUE;
00823   }
00824 
00825   jsrefcount saveDepth;
00826   saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
00827   //  public int FinalizeInstall (void);
00828   nsresult rv = nativeThis->FinalizeInstall(&nativeRet);
00829   JS_ResumeRequest(cx, saveDepth);
00830 
00831   if (NS_SUCCEEDED(rv))
00832     *rval = INT_TO_JSVAL(nativeRet);
00833 
00834   return JS_TRUE;
00835 }
00836 
00837 
00838 //
00839 // Native method Gestalt
00840 //
00841 PR_STATIC_CALLBACK(JSBool)
00842 InstallGestalt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00843 {
00844   nsInstall *nativeThis =
00845     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00846 
00847   PRInt32 nativeRet;
00848   nsAutoString b0;
00849 
00850   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
00851 
00852   // If there's no private data, this must be the prototype, so ignore
00853   if (nsnull == nativeThis) {
00854     return JS_TRUE;
00855   }
00856 
00857   if(argc >= 1)
00858   {
00859     //  public int Gestalt ( String selector,
00860     //                       long   *response);
00861 
00862     ConvertJSValToStr(b0, cx, argv[0]);
00863 
00864     if(NS_OK != nativeThis->Gestalt(b0, &nativeRet))
00865     {
00866       return JS_FALSE;
00867     }
00868 
00869     *rval = INT_TO_JSVAL(nativeRet);
00870   }
00871   else
00872   {
00873     JS_ReportError(cx, "Function Gestalt requires 1 parameters");
00874     return JS_FALSE;
00875   }
00876 
00877   return JS_TRUE;
00878 }
00879 
00880 
00881 //
00882 // Native method GetComponentFolder
00883 //
00884 PR_STATIC_CALLBACK(JSBool)
00885 InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00886 {
00887   nsInstall *nativeThis =
00888     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00889 
00890   nsInstallFolder* folder;
00891   nsAutoString b0;
00892   nsAutoString b1;
00893 
00894   *rval = JSVAL_NULL;
00895 
00896   // If there's no private data, this must be the prototype, so ignore
00897   if (nsnull == nativeThis) {
00898     return JS_TRUE;
00899   }
00900 
00901   if(argc >= 2)
00902   {
00903     //  public int GetComponentFolder ( String registryName,
00904     //                                  String subDirectory);
00905     ConvertJSValToStr(b0, cx, argv[0]);
00906     ConvertJSValToStr(b1, cx, argv[1]);
00907 
00908     if(NS_OK != nativeThis->GetComponentFolder(b0, b1, &folder))
00909     {
00910       // error!
00911       return JS_FALSE;
00912     }
00913   }
00914   else if(argc >= 1)
00915   {
00916     //  public int GetComponentFolder ( String registryName);
00917 
00918     ConvertJSValToStr(b0, cx, argv[0]);
00919 
00920     if(NS_OK != nativeThis->GetComponentFolder(b0, &folder))
00921     {
00922       // error!
00923       return JS_FALSE;
00924     }
00925   }
00926   else
00927   {
00928     JS_ReportError(cx, "Function GetComponentFolder requires 2 parameters");
00929     return JS_FALSE;
00930   }
00931 
00932   // if we couldn't find one return null rval from here
00933   if(nsnull == folder)
00934   {
00935     return JS_TRUE;
00936   }
00937 
00938   /* Now create the new JSObject */
00939   JSObject* fileSpecObject;
00940 
00941   fileSpecObject = JS_NewObject(cx, &FileSpecObjectClass, gFileSpecProto, NULL);
00942   if (fileSpecObject == NULL)
00943     return JS_FALSE;
00944 
00945   JS_SetPrivate(cx, fileSpecObject, folder);
00946   if (fileSpecObject == NULL)
00947     return JS_FALSE;
00948 
00949   *rval = OBJECT_TO_JSVAL(fileSpecObject);
00950 
00951   return JS_TRUE;
00952 }
00953 
00954 
00955 //
00956 // Native method GetFolder
00957 //
00958 PR_STATIC_CALLBACK(JSBool)
00959 InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
00960 {
00961   nsInstall *nativeThis =
00962     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
00963 
00964   JSObject *jsObj;
00965   nsAutoString b0;
00966   nsAutoString b1;
00967   nsInstallFolder *folder = nsnull;
00968 
00969   *rval = JSVAL_NULL;
00970 
00971   // If there's no private data, this must be the prototype, so ignore
00972   if (nsnull == nativeThis) {
00973     return JS_TRUE;
00974   }
00975 
00976   if(argc >= 2)
00977   {
00978     ConvertJSValToStr(b1, cx, argv[1]); // we know that the second param must be a string
00979     if(JSVAL_IS_STRING(argv[0])) // check if the first argument is a string
00980     {
00981       ConvertJSValToStr(b0, cx, argv[0]);
00982       if(NS_OK != nativeThis->GetFolder(b0, b1, &folder))
00983         return JS_TRUE;
00984     }
00985     else /* it must be an object */
00986     {
00987 
00988       if ((argv[0] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[0])) //argv[0] MUST be a jsval
00989       {
00990         *rval = JSVAL_NULL;
00991         JS_ReportError(cx, "GetFolder:Invalid Parameter");
00992         return JS_TRUE;
00993       }
00994 
00995       jsObj = JSVAL_TO_OBJECT(argv[0]);
00996       if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
00997       {
00998         *rval = JSVAL_NULL;
00999         JS_ReportError(cx, "GetFolder:Invalid Parameter");
01000         return JS_TRUE;
01001       }
01002 
01003       folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
01004       if (!folder)
01005       {
01006         JS_ReportError(cx, "GetFolder:Invalid Parameter");
01007         return JS_FALSE;
01008       }
01009       else if(NS_OK != nativeThis->GetFolder(*folder, b1, &folder))
01010         return JS_TRUE;
01011     }
01012 
01013     if(nsnull == folder)
01014       return JS_TRUE;
01015   }
01016   else if(argc >= 1)
01017   {
01018     //  public int GetFolder ( String folderName);
01019 
01020     ConvertJSValToStr(b0, cx, argv[0]);
01021 
01022     if(NS_OK != nativeThis->GetFolder(b0, &folder))
01023     {
01024       return JS_TRUE;
01025     }
01026 
01027     if(nsnull == folder)
01028       return JS_TRUE;
01029   }
01030   else
01031   {
01032     JS_ReportError(cx, "Function GetFolder requires at least 1 parameter");
01033     return JS_FALSE;
01034   }
01035 
01036   if ( folder )
01037   {
01038     /* Now create the new JSObject */
01039     JSObject* fileSpecObject;
01040 
01041     fileSpecObject = JS_NewObject(cx, &FileSpecObjectClass, gFileSpecProto, NULL);
01042     if (fileSpecObject == NULL)
01043       return JS_FALSE;
01044 
01045     JS_SetPrivate(cx, fileSpecObject, folder);
01046     if (fileSpecObject == NULL)
01047       return JS_FALSE;
01048 
01049     *rval = OBJECT_TO_JSVAL(fileSpecObject);
01050   }
01051 
01052 
01053   return JS_TRUE;
01054 }
01055 
01056 
01057 
01058 //
01059 // Native method GetLastError
01060 //
01061 PR_STATIC_CALLBACK(JSBool)
01062 InstallGetLastError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01063 {
01064   nsInstall *nativeThis =
01065     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01066 
01067   PRInt32 nativeRet;
01068 
01069 
01070   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01071 
01072   // If there's no private data, this must be the prototype, so ignore
01073   if (nsnull == nativeThis) {
01074     return JS_TRUE;
01075   }
01076 
01077   //  public int GetLastError (void);
01078 
01079   if(NS_OK == nativeThis->GetLastError(&nativeRet)) {
01080     *rval = INT_TO_JSVAL(nativeRet);
01081   }
01082 
01083   return JS_TRUE;
01084 }
01085 
01086 
01087 //
01088 // Native method GetWinProfile
01089 //
01090 PR_STATIC_CALLBACK(JSBool)
01091 InstallGetWinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01092 {
01093   *rval = JSVAL_NULL;
01094 
01095 #ifdef _WINDOWS
01096   nsInstall *nativeThis =
01097     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01098   if (!nativeThis)
01099     return JS_FALSE;
01100 
01101   nsAutoString b0;
01102   nsAutoString b1;
01103 
01104   if(argc >= 2)
01105   {
01106     //  public int GetWinProfile (Object folder,
01107     //                            String file);
01108 
01109     ConvertJSValToStr(b0, cx, argv[0]);
01110     ConvertJSValToStr(b1, cx, argv[1]);
01111 
01112     if(NS_OK != nativeThis->GetWinProfile(b0, b1, cx, &WinProfileClass, rval))
01113     {
01114       return JS_FALSE;
01115     }
01116   }
01117   else
01118   {
01119     JS_ReportError(cx, "Function GetWinProfile requires 0 parameters");
01120     return JS_FALSE;
01121   }
01122 #endif
01123 
01124   return JS_TRUE;
01125 }
01126 
01127 
01128 //
01129 // Native method GetWinRegistry
01130 //
01131 PR_STATIC_CALLBACK(JSBool)
01132 InstallGetWinRegistry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01133 {
01134   *rval = JSVAL_NULL;
01135 
01136 #ifdef _WINDOWS
01137 
01138   nsInstall *nativeThis =
01139     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01140   if (!nativeThis)
01141     return JS_FALSE;
01142 
01143   //  public int GetWinRegistry (void);
01144   if(NS_OK != nativeThis->GetWinRegistry(cx, &WinRegClass, rval))
01145   {
01146     *rval = JSVAL_NULL;
01147     return JS_TRUE;
01148   }
01149 #endif
01150 
01151   return JS_TRUE;
01152 }
01153 
01154 
01155 //
01156 // Native method LoadResources
01157 //
01158 PR_STATIC_CALLBACK(JSBool)
01159 InstallLoadResources(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01160 {
01161   nsInstall *nativeThis =
01162     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01163 
01164   nsAutoString b0;
01165 
01166   *rval = JSVAL_NULL;
01167 
01168   // If there's no private data, this must be the prototype, so ignore
01169   if (nsnull == nativeThis) {
01170     return JS_TRUE;
01171   }
01172 
01173   if (argc >= 1)
01174   {
01175     ConvertJSValToStr(b0, cx, argv[0]);
01176     if (NS_OK != nativeThis->LoadResources(cx, b0, rval))
01177     {
01178       return JS_FALSE;
01179     }
01180   }
01181   else
01182   {
01183     JS_ReportError(cx, "Function LoadResources requires 1 parameter");
01184     return JS_FALSE;
01185   }
01186 
01187   return JS_TRUE;
01188 }
01189 
01190 
01191 //
01192 // Native method Patch
01193 //
01194 PR_STATIC_CALLBACK(JSBool)
01195 InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01196 {
01197   nsInstall *nativeThis =
01198     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01199 
01200   PRInt32 nativeRet;
01201   nsAutoString b0;
01202   nsAutoString b1;
01203   nsAutoString b2;
01204   nsAutoString b3;
01205   nsAutoString b4;
01206 
01207   JSObject *jsObj;
01208 
01209   nsInstallFolder *folder = nsnull;
01210 
01211 
01212   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01213 
01214   // If there's no private data, this must be the prototype, so ignore
01215   if (nsnull == nativeThis) {
01216     return JS_TRUE;
01217   }
01218 
01219   if(argc >= 5)
01220   {
01221     //  public int Patch (String registryName,
01222     //                    String version,        --OR-- VersionInfo version,
01223     //                    String jarSourcePath,
01224     //                    Object localDirSpec,
01225     //                    String relativeLocalPath);
01226 
01227     ConvertJSValToStr(b0, cx, argv[0]);
01228     ConvertJSvalToVersionString(b1, cx, argv[1]);
01229     ConvertJSValToStr(b2, cx, argv[2]);
01230     ConvertJSValToStr(b3, cx, argv[4]);
01231 
01232     if ((argv[3] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[3])) //argv[3] MUST be a jsval
01233     {
01234       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01235       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01236       return JS_TRUE;
01237     }
01238 
01239     jsObj = JSVAL_TO_OBJECT(argv[3]);
01240     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
01241     {
01242       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01243       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01244       return JS_TRUE;
01245     }
01246 
01247     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
01248 
01249     if(NS_OK != nativeThis->Patch(b0, b1, b2, folder, b3, &nativeRet))
01250     {
01251         return JS_FALSE;
01252     }
01253 
01254     *rval = INT_TO_JSVAL(nativeRet);
01255   }
01256   else if(argc >= 4)
01257   {
01258     //  public int Patch (String registryName,
01259     //                    String jarSourcePath,
01260     //                    Object localDirSpec,
01261     //                    String relativeLocalPath);
01262 
01263     ConvertJSValToStr(b0, cx, argv[0]);
01264     ConvertJSValToStr(b1, cx, argv[1]);
01265     ConvertJSValToStr(b2, cx, argv[3]);
01266 
01267     if ((argv[2] == JSVAL_NULL) || !JSVAL_IS_OBJECT(argv[2])) //argv[2] MUST be a jsval
01268     {
01269       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01270       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01271       return JS_TRUE;
01272     }
01273 
01274     jsObj = JSVAL_TO_OBJECT(argv[2]);
01275     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
01276     {
01277       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01278       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01279       return JS_TRUE;
01280     }
01281 
01282     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
01283 
01284     if(NS_OK != nativeThis->Patch(b0, b1, folder, b2, &nativeRet))
01285     {
01286       return JS_FALSE;
01287     }
01288 
01289     *rval = INT_TO_JSVAL(nativeRet);
01290   }
01291   else
01292   {
01293     JS_ReportError(cx, "Function Patch requires 5 parameters");
01294     return JS_FALSE;
01295   }
01296 
01297   return JS_TRUE;
01298 }
01299 
01300 //
01301 // Native method RegisterChrome
01302 //
01303 //    int registerChrome(
01304 //         int  type,
01305 //         FileSpecObject chrome,
01306 //         String extraPath)
01307 PR_STATIC_CALLBACK(JSBool)
01308 InstallRegisterChrome(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01309 {
01310   // If there's no private data, this must be the prototype, so ignore
01311   nsInstall *nativeThis =
01312     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01313 
01314   if (nsnull == nativeThis) {
01315     *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01316     return JS_TRUE;
01317   }
01318 
01319   // Now validate the arguments
01320   uint32 chromeType = 0;
01321   nsIFile* chrome = nsnull;
01322   if ( argc >=2 )
01323   {
01324     JS_ValueToECMAUint32(cx, argv[0], &chromeType);
01325 
01326     if (argv[1] != JSVAL_NULL && JSVAL_IS_OBJECT(argv[1]))
01327     {
01328       JSObject* jsObj = JSVAL_TO_OBJECT(argv[1]);
01329       if (JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
01330       {
01331         nsInstallFolder* folder = (nsInstallFolder*)JS_GetPrivate(cx,jsObj);
01332         if (folder)
01333         {
01334           chrome = folder->GetFileSpec();
01335         }
01336       }
01337     }
01338   }
01339   nsAutoString path;
01340   if (argc >= 3) {
01341     ConvertJSValToStr(path, cx, argv[2]);
01342   }
01343 
01344   *rval = INT_TO_JSVAL(nativeThis->RegisterChrome(chrome, chromeType, NS_ConvertUCS2toUTF8(path).get()));
01345 
01346   return JS_TRUE;
01347 }
01348 
01349 
01350 //
01351 // Native method RefreshPlugins
01352 //
01353 PR_STATIC_CALLBACK(JSBool)
01354 InstallRefreshPlugins(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01355 {
01356   nsInstall *nativeThis =
01357     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01358 
01359   // If there's no private data, this must be the prototype, so ignore
01360   if (!nativeThis)
01361   {
01362     *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01363   }
01364   else
01365   {
01366     PRBool reloadPages = PR_TRUE;
01367     if (argc >= 1)
01368       reloadPages = JSVAL_TO_BOOLEAN(argv[0]);
01369 
01370     *rval = INT_TO_JSVAL(nativeThis->RefreshPlugins(reloadPages));
01371   }
01372   return JS_TRUE;
01373 }
01374 
01375 
01376 //
01377 // Native method ResetError
01378 //
01379 PR_STATIC_CALLBACK(JSBool)
01380 InstallResetError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01381 {
01382   nsInstall *nativeThis =
01383     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01384 
01385   *rval = JSVAL_VOID;
01386 
01387   // If there's no private data, this must be the prototype, so ignore
01388   if (!nativeThis)
01389     return JS_TRUE;
01390 
01391   // Supported forms:
01392   //    void resetError()
01393   //    void resetError(int error)
01394   int32 val = 0;
01395   if ( argc >= 1 )
01396     JS_ValueToECMAInt32(cx, argv[0], &val);
01397 
01398   nativeThis->ResetError(val);
01399   return JS_TRUE;
01400 }
01401 
01402 
01403 //
01404 // Native method SetPackageFolder
01405 //
01406 PR_STATIC_CALLBACK(JSBool)
01407 InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01408 {
01409   nsInstall *nativeThis =
01410     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01411 
01412   nsAutoString b0;
01413   JSObject *jsObj;
01414   nsInstallFolder *folder;
01415 
01416   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01417 
01418   // If there's no private data, this must be the prototype, so ignore
01419   if (nsnull == nativeThis) {
01420     return JS_TRUE;
01421   }
01422 
01423   if(argc >= 1)
01424   {
01425     //  public int SetPackageFolder (Object folder);
01426 
01427     if ((argv[0] == JSVAL_NULL)  || !JSVAL_IS_OBJECT(argv[0])) //argv[0] MUST be a jsval
01428     {
01429       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01430       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01431       return JS_TRUE;
01432     }
01433 
01434     jsObj = JSVAL_TO_OBJECT(argv[0]);
01435     if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
01436     {
01437       *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS);
01438       nativeThis->SaveError(nsInstall::INVALID_ARGUMENTS);
01439       return JS_TRUE;
01440     }
01441 
01442     folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
01443     if (!folder)
01444     {
01445       JS_ReportError(cx, "setPackageFolder:Invalid Parameter");
01446       return JS_FALSE;
01447     }
01448     else
01449       if(NS_OK != nativeThis->SetPackageFolder(*folder))
01450         return JS_FALSE;
01451 
01452     *rval = JSVAL_ZERO;
01453   }
01454   else
01455   {
01456     JS_ReportError(cx, "Function SetPackageFolder requires 1 parameters");
01457     return JS_FALSE;
01458   }
01459 
01460   return JS_TRUE;
01461 }
01462 
01463 //
01464 // Native method StartInstall
01465 //
01466 PR_STATIC_CALLBACK(JSBool)
01467 InstallStartInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01468 {
01469   nsInstall *nativeThis =
01470     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01471 
01472   PRInt32 nativeRet;
01473   nsAutoString b0;
01474   nsAutoString b1;
01475   nsAutoString b2;
01476 
01477   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01478 
01479   // If there's no private data, this must be the prototype, so ignore
01480   if (nsnull == nativeThis) {
01481     return JS_TRUE;
01482   }
01483 
01484   if(argc == 3 || argc == 4)
01485   {
01486     //  public int StartInstall (String userPackageName,
01487     //                           String package,
01488     //                           String version); --OR-- VersionInfo version
01489     //                           flags?
01490     ConvertJSValToStr(b0, cx, argv[0]);
01491     ConvertJSValToStr(b1, cx, argv[1]);
01492     ConvertJSvalToVersionString(b2, cx, argv[2]);
01493 
01494     jsrefcount saveDepth;
01495     saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
01496 
01497     nsresult rv = nativeThis->StartInstall(b0, b1, b2, &nativeRet);
01498 
01499     JS_ResumeRequest(cx, saveDepth); //Resume the suspened thread
01500     if (NS_FAILED(rv))
01501     {
01502         return JS_FALSE;
01503     }
01504 
01505     *rval = INT_TO_JSVAL(nativeRet);
01506   }
01507   else
01508   {
01509     JS_ReportError(cx, "Function StartInstall requires 3 parameters");
01510     return JS_FALSE;
01511   }
01512 
01513   return JS_TRUE;
01514 }
01515 
01516 
01517 //
01518 // Native method Uninstall
01519 //
01520 PR_STATIC_CALLBACK(JSBool)
01521 InstallUninstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01522 {
01523   nsInstall *nativeThis =
01524     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01525 
01526   PRInt32 nativeRet;
01527   nsAutoString b0;
01528 
01529   *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
01530 
01531   // If there's no private data, this must be the prototype, so ignore
01532   if (nsnull == nativeThis) {
01533     return JS_TRUE;
01534   }
01535 
01536   if(argc >= 1)
01537   {
01538     //  public int Uninstall (String packageName);
01539 
01540     ConvertJSValToStr(b0, cx, argv[0]);
01541 
01542     if(NS_OK != nativeThis->Uninstall(b0, &nativeRet))
01543     {
01544       return JS_FALSE;
01545     }
01546 
01547     *rval = INT_TO_JSVAL(nativeRet);
01548   }
01549   else
01550   {
01551     JS_ReportError(cx, "Function Uninstall requires 1 parameters");
01552     return JS_FALSE;
01553   }
01554 
01555   return JS_TRUE;
01556 }
01557 
01558 
01559 /*START HACK FOR DEBUGGING UNTIL ALERTS WORK*/
01560 
01561 PR_STATIC_CALLBACK(JSBool)
01562 InstallTRACE(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01563 {
01564   nsAutoString b0;
01565 
01566   ConvertJSValToStr(b0, cx, argv[0]);
01567 
01568   char *tempStr;
01569   tempStr = ToNewCString(b0);
01570   printf("Install:\t%s\n", tempStr);
01571 
01572   Recycle(tempStr);
01573 
01574   return JS_TRUE;
01575 }
01576 
01577 /*END HACK FOR DEBUGGING UNTIL ALERTS WORK*/
01578 
01579 
01580 //
01581 // Native method LogComment
01582 //
01583 PR_STATIC_CALLBACK(JSBool)
01584 InstallLogComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01585 {
01586   nsInstall *nativeThis =
01587     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01588   if (!nativeThis)
01589     return JS_FALSE;
01590 
01591   nsAutoString b0;
01592 
01593   *rval = JSVAL_NULL;
01594 
01595   if(argc >= 1)
01596   {
01597     //  public int LogComment (String aComment);
01598 
01599     ConvertJSValToStr(b0, cx, argv[0]);
01600 
01601     nativeThis->LogComment(b0);
01602   }
01603   else
01604   {
01605     JS_ReportError(cx, "Function LogComment requires 1 parameter");
01606     return JS_FALSE;
01607   }
01608 
01609   return JS_TRUE;
01610 }
01611 
01612 
01613 //
01614 // Native method InstallAlert
01615 //
01616 PR_STATIC_CALLBACK(JSBool)
01617 InstallAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01618 {
01619   nsInstall *nativeThis =
01620     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01621   if (!nativeThis)
01622     return JS_FALSE;
01623 
01624   nsAutoString b0;
01625 
01626   *rval = JSVAL_NULL;
01627 
01628   if(argc == 1)
01629   {
01630     //  public int InstallAlert (String aComment);
01631 
01632     ConvertJSValToStr(b0, cx, argv[0]);
01633 
01634     jsrefcount saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs
01635 
01636     nativeThis->Alert(b0);
01637     JS_ResumeRequest(cx, saveDepth);
01638 
01639   }
01640   else
01641   {
01642     JS_ReportError(cx, "Function Alert requires 1 parameter");
01643     return JS_FALSE;
01644   }
01645 
01646   return JS_TRUE;
01647 }
01648 
01649 //
01650 // Native method InstallConfirm
01651 //
01652 PR_STATIC_CALLBACK(JSBool)
01653 InstallConfirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
01654 {
01655   nsInstall *nativeThis =
01656     (nsInstall*)JS_GetInstancePrivate(cx, obj, &InstallClass, argv);
01657   if (!nativeThis)
01658     return JS_FALSE;
01659 
01660   nsAutoString text;
01661   nsAutoString title;
01662   PRUint32 buttonFlags = nsIPromptService::STD_OK_CANCEL_BUTTONS;
01663   nsAutoString button0Title;
01664   nsAutoString button1Title;
01665   nsAutoString button2Title;
01666   nsAutoString checkMsg;
01667   JSObject* checkObj = 0;
01668   jsval jsCheckState = 0;
01669   PRBool checkState = PR_FALSE;
01670   PRInt32 nativeRet;
01671 
01672   *rval = JSVAL_FALSE;
01673 
01674   if(argc == 0)
01675   {
01676     JS_ReportError(cx, "Function Confirm requires at least 1 parameter");
01677     return JS_FALSE;
01678   }
01679 
01680   //  public int InstallConfirm (String aComment);
01681   ConvertJSValToStr(text, cx, argv[0]);
01682 
01683   //  Any additional parameters are optional.
01684   //  public int InstallConfirm (String aText,
01685   //                             String aDialogTitle,
01686   //                             Number aButtonFlags,
01687   //                             String aButton0Title,
01688   //                             String aButton1Title,
01689   //                             String aButton2Title,
01690   //                             String aCheckMsg,
01691   //                             Object aCheckState);
01692   if (argc > 1)
01693     ConvertJSValToStr(title, cx, argv[1]);
01694 
01695   if(argc > 2)
01696   {
01697     if(!JSVAL_IS_INT(argv[2]))
01698     {
01699       JS_ReportError(cx, "Parameter 'aButtonFlags' must be a number");
01700       return JS_FALSE;
01701     }
01702     buttonFlags = JSVAL_TO_INT(argv[2]);
01703   }
01704 
01705   if (argc > 3)
01706     ConvertJSValToStr(button0Title, cx, argv[3]);
01707   if (argc > 4)
01708     ConvertJSValToStr(button1Title, cx, argv[4]);
01709   if (argc > 5)
01710     ConvertJSValToStr(button2Title, cx, argv[5]);
01711   if (argc > 6)
01712     ConvertJSValToStr(checkMsg, cx, argv[6]);
01713 
01714   if (argc > 7 && !JSVAL_IS_PRIMITIVE(argv[7])) 
01715   {
01716     checkObj = JSVAL_TO_OBJECT(argv[7]);
01717     if (!JS_GetProperty(cx, checkObj, "value", &jsCheckState) ||
01718       !JSVAL_IS_BOOLEAN(jsCheckState))
01719     {
01720       JS_ReportError(cx, "Parameter 'aCheckState' must have a boolean 'value' property");
01721       return JS_FALSE;
01722     }
01723     JS_ValueToBoolean(cx, jsCheckState, &checkState);
01724   }
01725 
01726   jsrefcount saveDepth = JS_SuspendRequest(cx); //Need to suspend use of thread or deadlock occurs
01727 
01728   nativeThis->ConfirmEx(title, text, buttonFlags, button0Title, button1Title, button2Title, checkMsg, &checkState, &nativeRet);
01729 
01730   JS_ResumeRequest(cx, saveDepth);
01731 
01732   // Only save back checkState when an object was passed as 8th parameter
01733   if (checkObj)
01734   {
01735     jsCheckState = BOOLEAN_TO_JSVAL(checkState);
01736     JS_SetProperty(cx, checkObj, "value", &jsCheckState);
01737   }
01738 
01739   // To maintain compatibility with the classic one-arg confirm that returned 1
01740   // for OK and 0 for cancel/close, we have to swap 0 and 1 here, as confirmEx
01741   // always returns 0 for the first (i.e. OK) button.
01742   if (nativeRet == 0)
01743     nativeRet = 1; // 0 = first button = OK => true(1)
01744   else if (nativeRet == 1)
01745     nativeRet = 0; // 1 = second button or window closed = Cancel => false(0)
01746 
01747   *rval = INT_TO_JSVAL(nativeRet);
01748 
01749   return JS_TRUE;
01750 }
01751 
01752 //
01753 // Install class properties
01754 //
01755 static JSPropertySpec InstallProperties[] =
01756 {
01757   {"platform",          INSTALL_PLATFORM,           JSPROP_ENUMERATE | JSPROP_READONLY},
01758   {"jarfile",           INSTALL_JARFILE,            JSPROP_ENUMERATE | JSPROP_READONLY},
01759   {"archive",           INSTALL_ARCHIVE,            JSPROP_ENUMERATE | JSPROP_READONLY},
01760   {"arguments",         INSTALL_ARGUMENTS,          JSPROP_ENUMERATE | JSPROP_READONLY},
01761   {"url",               INSTALL_URL,                JSPROP_ENUMERATE | JSPROP_READONLY},
01762   {"flags",             INSTALL_FLAGS,              JSPROP_ENUMERATE | JSPROP_READONLY},
01763   {"_finalStatus",      INSTALL_FINALSTATUS,        JSPROP_READONLY},
01764   {"Install",           INSTALL_INSTALL,            JSPROP_READONLY},
01765   {"_installedFiles",   INSTALL_INSTALLED_FILES,    JSPROP_READONLY},
01766   {0}
01767 };
01768 
01769 
01770 static JSConstDoubleSpec install_constants[] =
01771 {
01772     { nsInstall::BAD_PACKAGE_NAME,           "BAD_PACKAGE_NAME"             },
01773     { nsInstall::UNEXPECTED_ERROR,           "UNEXPECTED_ERROR"             },
01774     { nsInstall::ACCESS_DENIED,              "ACCESS_DENIED"                },
01775     { nsInstall::EXECUTION_ERROR,            "EXECUTION_ERROR"              },
01776     { nsInstall::NO_INSTALL_SCRIPT,          "NO_INSTALL_SCRIPT"            },
01777 
01778 
01779     { nsInstall::CANT_READ_ARCHIVE,          "CANT_READ_ARCHIVE"            },
01780     { nsInstall::INVALID_ARGUMENTS,          "INVALID_ARGUMENTS"            },
01781 
01782     { nsInstall::USER_CANCELLED,             "USER_CANCELLED"               },
01783     { nsInstall::INSTALL_NOT_STARTED,        "INSTALL_NOT_STARTED"          },
01784 
01785     { nsInstall::NO_SUCH_COMPONENT,          "NO_SUCH_COMPONENT"            },
01786     { nsInstall::DOES_NOT_EXIST,             "DOES_NOT_EXIST"               },
01787     { nsInstall::READ_ONLY,                  "READ_ONLY"                    },
01788     { nsInstall::IS_DIRECTORY,               "IS_DIRECTORY"                 },
01789     { nsInstall::NETWORK_FILE_IS_IN_USE,     "NETWORK_FILE_IS_IN_USE"       },
01790     { nsInstall::APPLE_SINGLE_ERR,           "APPLE_SINGLE_ERR"             },
01791 
01792     { nsInstall::PATCH_BAD_DIFF,             "PATCH_BAD_DIFF"               },
01793     { nsInstall::PATCH_BAD_CHECKSUM_TARGET,  "PATCH_BAD_CHECKSUM_TARGET"    },
01794     { nsInstall::PATCH_BAD_CHECKSUM_RESULT,  "PATCH_BAD_CHECKSUM_RESULT"    },
01795     { nsInstall::UNINSTALL_FAILED,           "UNINSTALL_FAILED"             },
01796     { nsInstall::PACKAGE_FOLDER_NOT_SET,     "PACKAGE_FOLDER_NOT_SET"       },
01797     { nsInstall::EXTRACTION_FAILED,          "EXTRACTION_FAILED"            },
01798     { nsInstall::FILENAME_ALREADY_USED,      "FILENAME_ALREADY_USED"        },
01799     { nsInstall::INSTALL_CANCELLED,          "INSTALL_CANCELLED"            },
01800     { nsInstall::DOWNLOAD_ERROR,             "DOWNLOAD_ERROR"               },
01801     { nsInstall::SCRIPT_ERROR,               "SCRIPT_ERROR"                 },
01802     { nsInstall::ALREADY_EXISTS,             "ALREADY_EXISTS"               },
01803     { nsInstall::IS_FILE,                    "IS_FILE"                      },
01804     { nsInstall::SOURCE_DOES_NOT_EXIST,      "SOURCE_DOES_NOT_EXIST"        },
01805     { nsInstall::SOURCE_IS_DIRECTORY,        "SOURCE_IS_DIRECTORY"          },
01806     { nsInstall::SOURCE_IS_FILE,             "SOURCE_IS_FILE"               },
01807     { nsInstall::INSUFFICIENT_DISK_SPACE,    "INSUFFICIENT_DISK_SPACE"      },
01808 
01809     { nsInstall::UNABLE_TO_LOCATE_LIB_FUNCTION, "UNABLE_TO_LOCATE_LIB_FUNCTION"},
01810     { nsInstall::UNABLE_TO_LOAD_LIBRARY,     "UNABLE_TO_LOAD_LIBRARY"       },
01811     { nsInstall::CHROME_REGISTRY_ERROR,      "CHROME_REGISTRY_ERROR"        },
01812     { nsInstall::MALFORMED_INSTALL,          "MALFORMED_INSTALL"            },
01813 
01814     { nsInstall::KEY_ACCESS_DENIED,          "KEY_ACCESS_DENIED"            },
01815     { nsInstall::KEY_DOES_NOT_EXIST,         "KEY_DOES_NOT_EXIST"           },
01816     { nsInstall::VALUE_DOES_NOT_EXIST,       "VALUE_DOES_NOT_EXIST"         },
01817 
01818     { nsInstall::GESTALT_UNKNOWN_ERR,        "GESTALT_UNKNOWN_ERR"          },
01819     { nsInstall::GESTALT_INVALID_ARGUMENT,   "GESTALT_INVALID_ARGUMENT"     },
01820 
01821     { nsInstall::SUCCESS,                    "SUCCESS"                      },
01822     { nsInstall::REBOOT_NEEDED,              "REBOOT_NEEDED"                },
01823     { nsInstall::INVALID_SIGNATURE,          "INVALID_SIGNATURE"            },
01824     { nsInstall::INVALID_HASH,               "INVALID_HASH"                 },
01825     { nsInstall::INVALID_HASH_TYPE,          "INVALID_HASH_TYPE"            },
01826 
01827     // these are flags supported by confirm
01828     { nsIPromptService::BUTTON_POS_0,            "BUTTON_POS_0"             },
01829     { nsIPromptService::BUTTON_POS_1,            "BUTTON_POS_1"             },
01830     { nsIPromptService::BUTTON_POS_2,            "BUTTON_POS_2"             },
01831     { nsIPromptService::BUTTON_TITLE_OK,         "BUTTON_TITLE_OK"          },
01832     { nsIPromptService::BUTTON_TITLE_CANCEL,     "BUTTON_TITLE_CANCEL"      },
01833     { nsIPromptService::BUTTON_TITLE_YES,        "BUTTON_TITLE_YES"         },
01834     { nsIPromptService::BUTTON_TITLE_NO,         "BUTTON_TITLE_NO"          },
01835     { nsIPromptService::BUTTON_TITLE_SAVE,       "BUTTON_TITLE_SAVE"        },
01836     { nsIPromptService::BUTTON_TITLE_DONT_SAVE,  "BUTTON_TITLE_DONT_SAVE"   },
01837     { nsIPromptService::BUTTON_TITLE_REVERT,     "BUTTON_TITLE_REVERT"      },
01838     { nsIPromptService::BUTTON_TITLE_IS_STRING,  "BUTTON_TITLE_IS_STRING"   },
01839     { nsIPromptService::BUTTON_POS_0_DEFAULT,    "BUTTON_POS_0_DEFAULT"     },
01840     { nsIPromptService::BUTTON_POS_1_DEFAULT,    "BUTTON_POS_1_DEFAULT"     },
01841     { nsIPromptService::BUTTON_POS_2_DEFAULT,    "BUTTON_POS_2_DEFAULT"     },
01842     { nsIPromptService::BUTTON_DELAY_ENABLE,     "BUTTON_DELAY_ENABLE"      },
01843     { nsIPromptService::STD_OK_CANCEL_BUTTONS,   "STD_OK_CANCEL_BUTTONS"    },
01844     { nsIPromptService::STD_YES_NO_BUTTONS,      "STD_YES_NO_BUTTONS"       },
01845 
01846     // these are bitwise values supported by addFile
01847     { DO_NOT_UNINSTALL,                      "DO_NOT_UNINSTALL"             },
01848     { WIN_SHARED_FILE,                       "WIN_SHARED_FILE"              },
01849     { WIN_SYSTEM_FILE,                       "WIN_SYSTEM_FILE"              },
01850 
01851     { CHROME_SKIN,                           "SKIN"                         },
01852     { CHROME_LOCALE,                         "LOCALE"                       },
01853     { CHROME_CONTENT,                        "CONTENT"                      },
01854     { CHROME_ALL,                            "PACKAGE"                      },
01855     { CHROME_PROFILE,                        "PROFILE_CHROME"               },
01856     { CHROME_DELAYED,                        "DELAYED_CHROME"               },
01857     { CHROME_SELECT,                         "SELECT_CHROME"                },
01858 
01859     { NS_BUILD_ID,                           "buildID"                      },
01860 
01861     {0}
01862 };
01863 
01864 //
01865 // Install class methods
01866 //
01867 static JSFunctionSpec InstallMethods[] =
01868 {
01869 /*START HACK FOR DEBUGGING UNTIL ALERTS WORK*/
01870   {"TRACE",                     InstallTRACE,                   1},
01871 /*END HACK FOR DEBUGGING UNTIL ALERTS WORK*/
01872   // -- new forms that match prevailing javascript style --
01873   {"addDirectory",              InstallAddDirectory,            6},
01874   {"addFile",                   InstallAddSubcomponent,         6},
01875   {"alert",                     InstallAlert,                   1},
01876   {"cancelInstall",             InstallAbortInstall,            1},
01877   {"confirm",                   InstallConfirm,                 8},
01878   {"execute",                   InstallExecute,                 2},
01879   {"gestalt",                   InstallGestalt,                 1},
01880   {"getComponentFolder",        InstallGetComponentFolder,      2},
01881   {"getFolder",                 InstallGetFolder,               2},
01882   {"getLastError",              InstallGetLastError,            0},
01883   {"getWinProfile",             InstallGetWinProfile,           2},
01884   {"getWinRegistry",            InstallGetWinRegistry,          0},
01885   {"initInstall",               InstallStartInstall,            4},
01886   {"loadResources",             InstallLoadResources,           1},
01887   {"logComment",                InstallLogComment,              1},
01888   {"patch",                     InstallPatch,                   5},
01889   {"performInstall",            InstallFinalizeInstall,         0},
01890   {"registerChrome",            InstallRegisterChrome,          2},
01891   {"refreshPlugins",            InstallRefreshPlugins,          1},
01892   {"resetError",                InstallResetError,              1},
01893 //  {"selectChrome",              InstallSelectChrome,            2},
01894   {"setPackageFolder",          InstallSetPackageFolder,        1},
01895   {"uninstall",                 InstallUninstall,               1},
01896 
01897   // the raw file methods are deprecated, use the File object instead
01898   {"dirCreate",                 InstallFileOpDirCreate,                1},
01899   {"dirGetParent",              InstallFileOpDirGetParent,             1},
01900   {"dirRemove",                 InstallFileOpDirRemove,                2},
01901   {"dirRename",                 InstallFileOpDirRename,                2},
01902   {"fileCopy",                  InstallFileOpFileCopy,                 2},
01903   {"fileDelete",                InstallFileOpFileRemove,               1},
01904   {"fileExists",                InstallFileOpFileExists,               1},
01905   {"fileExecute",               InstallFileOpFileExecute,              2},
01906   {"fileGetNativeVersion",      InstallFileOpFileGetNativeVersion,     1},
01907   {"fileGetDiskSpaceAvailable", InstallFileOpFileGetDiskSpaceAvailable,1},
01908   {"fileGetModDate",            InstallFileOpFileGetModDate,           1},
01909   {"fileGetSize",               InstallFileOpFileGetSize,              1},
01910   {"fileIsDirectory",           InstallFileOpFileIsDirectory,          1},
01911   {"fileIsWritable",            InstallFileOpFileIsWritable,           1},
01912   {"fileIsFile",                InstallFileOpFileIsFile,               1},
01913   {"fileModDateChanged",        InstallFileOpFileModDateChanged,       2},
01914   {"fileMove",                  InstallFileOpFileMove,                 2},
01915   {"fileRename",                InstallFileOpFileRename,               2},
01916   {"fileWindowsShortcut",       InstallFileOpFileWindowsShortcut,      7},
01917   {"fileMacAlias",              InstallFileOpFileMacAlias,             2},
01918   {"fileUnixLink",              InstallFileOpFileUnixLink,             2},
01919 
01920   // -- documented but never supported --
01921   {"deleteRegisteredFile",      InstallDeleteComponent,         1},
01922 
01923   // -- obsolete forms for temporary compatibility --
01924   {"abortInstall",              InstallAbortInstall,            1},
01925   {"finalizeInstall",           InstallFinalizeInstall,         0},
01926   {"startInstall",              InstallStartInstall,            4},
01927   {0}
01928 };
01929 
01930 
01931 JSObject * InitXPInstallObjects(JSContext *jscontext,
01932                              nsIFile* jarfile,
01933                              const PRUnichar* url,
01934                              const PRUnichar* args,
01935                              PRUint32 flags,
01936                              CHROMEREG_IFACE* reg,
01937                              nsIZipReader * theJARFile)
01938 {
01939   JSObject *installObject;
01940   nsInstall *nativeInstallObject;
01941 
01942   // new global object
01943   installObject = JS_NewObject(jscontext, &InstallClass, nsnull, nsnull);
01944   if (!installObject)
01945     return nsnull;
01946 
01947   if (!JS_DefineProperty(jscontext, installObject, InstallClass.name,
01948                          OBJECT_TO_JSVAL(installObject), NULL, NULL, 0))
01949     return nsnull;
01950 
01951   if (!JS_DefineProperties(jscontext, installObject, InstallProperties))
01952     return nsnull;
01953 
01954   if (!JS_DefineFunctions(jscontext, installObject, InstallMethods))
01955     return nsnull;
01956 
01957   if (!JS_DefineConstDoubles(jscontext, installObject, install_constants))
01958     return nsnull;
01959 
01960   nativeInstallObject = new nsInstall(theJARFile);
01961   if (!nativeInstallObject)
01962     return nsnull;
01963 
01964   nativeInstallObject->SetJarFileLocation(jarfile);
01965   nativeInstallObject->SetInstallArguments(nsAutoString(args));
01966   nativeInstallObject->SetInstallURL(nsAutoString(url));
01967   nativeInstallObject->SetInstallFlags(flags);
01968   nativeInstallObject->SetChromeRegistry(reg);
01969 
01970   JS_SetPrivate(jscontext, installObject, nativeInstallObject);
01971   nativeInstallObject->SetScriptObject(installObject);
01972 
01973 
01974   //
01975   // Initialize and create the FileOp object
01976   //
01977   if(NS_OK != InitXPFileOpObjectPrototype(jscontext, installObject, &gFileOpProto))
01978   {
01979     return nsnull;
01980   }
01981 
01982   gFileOpObject = JS_NewObject(jscontext, &FileOpClass, gFileOpProto, nsnull);
01983   if (gFileOpObject == nsnull)
01984     return nsnull;
01985 
01986   JS_SetPrivate(jscontext, gFileOpObject, nativeInstallObject);
01987 
01988   if (!JS_DefineProperty (jscontext,
01989                           installObject,
01990                           "File", 
01991                           OBJECT_TO_JSVAL(gFileOpObject),
01992                           JS_PropertyStub, 
01993                           JS_PropertyStub, 
01994                           JSPROP_READONLY | JSPROP_PERMANENT))
01995     return nsnull;
01996 
01997   //
01998   // Initialize the FileSpecObject
01999   //
02000   if(NS_OK != InitFileSpecObjectPrototype(jscontext, installObject, &gFileSpecProto))
02001   {
02002     return nsnull;
02003   }
02004 
02005 
02006   //
02007   // Initialize platform specific helper objects
02008   //
02009 #ifdef _WINDOWS
02010   JSObject *winRegPrototype     = nsnull;
02011   JSObject *winProfilePrototype = nsnull;
02012 
02013   if(NS_OK != InitWinRegPrototype(jscontext, installObject, &winRegPrototype))
02014   {
02015     return nsnull;
02016   }
02017   nativeInstallObject->SaveWinRegPrototype(winRegPrototype);
02018 
02019   if(NS_OK != InitWinProfilePrototype(jscontext, installObject, &winProfilePrototype))
02020   {
02021     return nsnull;
02022   }
02023   nativeInstallObject->SaveWinProfilePrototype(winProfilePrototype);
02024 #endif
02025 
02026   return installObject;
02027 }
02028