diff --git a/xpinstall/src/Makefile.in b/xpinstall/src/Makefile.in index 4a5c3d3ba60b..f88b90db2452 100644 --- a/xpinstall/src/Makefile.in +++ b/xpinstall/src/Makefile.in @@ -61,6 +61,7 @@ CPPSRCS = \ nsXPITriggerInfo.cpp \ nsXPInstallManager.cpp \ nsInstallFileOpItem.cpp \ + nsJSFileSpecObj.cpp \ $(NULL) LOCAL_INCLUDES = -I$(srcdir)/../public diff --git a/xpinstall/src/makefile.win b/xpinstall/src/makefile.win index c5e3cfc66384..51411efa23fa 100644 --- a/xpinstall/src/makefile.win +++ b/xpinstall/src/makefile.win @@ -89,6 +89,7 @@ OBJS = \ .\$(OBJDIR)\nsXPInstallManager.obj \ .\$(OBJDIR)\nsInstallFileOpItem.obj \ .\$(OBJDIR)\nsWinShortcut.obj \ + .\$(OBJDIR)\nsJSFileSpecObj.obj \ $(NULL) WIN_LIBS= \ diff --git a/xpinstall/src/nsAppleSingleDecoder.cpp b/xpinstall/src/nsAppleSingleDecoder.cpp index a3b891553544..ff4e6982bb8e 100644 --- a/xpinstall/src/nsAppleSingleDecoder.cpp +++ b/xpinstall/src/nsAppleSingleDecoder.cpp @@ -32,13 +32,17 @@ /*----------------------------------------------------------------------* * Constructors/Destructor *----------------------------------------------------------------------*/ +MOZ_DECL_CTOR_COUNTER(nsAppleSingleDecoder); + nsAppleSingleDecoder::nsAppleSingleDecoder(FSSpec *inSpec, FSSpec *outSpec) : mInSpec(NULL), mOutSpec(NULL), mInRefNum(0), mRenameReqd(false) { - if (inSpec && outSpec) + MOZ_COUNT_CTOR(nsAppleSingleDecoder); + + if (inSpec && outSpec) { /* merely point to FSSpecs, not own 'em */ mInSpec = inSpec; @@ -52,11 +56,13 @@ nsAppleSingleDecoder::nsAppleSingleDecoder() mInRefNum(0), mRenameReqd(false) { + MOZ_COUNT_CTOR(nsAppleSingleDecoder); } nsAppleSingleDecoder::~nsAppleSingleDecoder() { /* not freeing FSSpecs since we don't own 'em */ + MOZ_COUNT_DTOR(nsAppleSingleDecoder); } diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index f199c8be5b39..993ced44f27d 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -73,6 +73,7 @@ #include "nsAppleSingleDecoder.h" #endif + static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); @@ -83,6 +84,8 @@ static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); #define XPINSTALL_BUNDLE_URL "chrome://xpinstall/locale/xpinstall.properties" +MOZ_DECL_CTOR_COUNTER(nsInstallInfo); + nsInstallInfo::nsInstallInfo(nsIFileSpec* aFile, const PRUnichar* aURL, const PRUnichar* aArgs, @@ -94,12 +97,15 @@ nsInstallInfo::nsInstallInfo(nsIFileSpec* aFile, mArgs(aArgs), mFile(aFile), mNotifier(aNotifier) -{} +{ + MOZ_COUNT_CTOR(nsInstallInfo); +} nsInstallInfo::~nsInstallInfo() { + MOZ_COUNT_DTOR(nsInstallInfo); } nsresult @@ -120,8 +126,12 @@ static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID); static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID); +MOZ_DECL_CTOR_COUNTER(nsInstall); + nsInstall::nsInstall() { + MOZ_COUNT_CTOR(nsInstall); + mScriptObject = nsnull; // this is the jsobject for our context mVersionInfo = nsnull; // this is the version information passed to us in StartInstall() mInstalledFiles = nsnull; // the list of installed objects @@ -170,6 +180,8 @@ nsInstall::~nsInstall() { if (mVersionInfo != nsnull) delete mVersionInfo; + + MOZ_COUNT_DTOR(nsInstall); } PRInt32 @@ -206,6 +218,7 @@ nsInstall::RetrieveWinProfilePrototype() } #endif + PRInt32 nsInstall::GetUserPackageName(nsString& aUserPackageName) { @@ -254,7 +267,7 @@ PRInt32 nsInstall::AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder *aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn) @@ -262,7 +275,7 @@ nsInstall::AddDirectory(const nsString& aRegName, nsInstallFile* ie = nsnull; PRInt32 result; - if ( aJarSource.Equals("") || aFolder.Equals("") ) + if ( aJarSource.Equals("") || aFolder == nsnull ) { *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); return NS_OK; @@ -395,7 +408,7 @@ PRInt32 nsInstall::AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder *aFolder, const nsString& aSubdir, PRInt32* aReturn) { @@ -411,7 +424,7 @@ nsInstall::AddDirectory(const nsString& aRegName, PRInt32 nsInstall::AddDirectory(const nsString& aRegName, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder *aFolder, const nsString& aSubdir, PRInt32* aReturn) { @@ -431,19 +444,17 @@ nsInstall::AddDirectory(const nsString& aJarSource, return AddDirectory("", "", aJarSource, - "", + nsnull, "", PR_FALSE, aReturn); - - } PRInt32 nsInstall::AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder *aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn) @@ -456,7 +467,7 @@ nsInstall::AddSubcomponent(const nsString& aRegName, PRInt32 errcode = nsInstall::SUCCESS; - if(aJarSource.Equals("") || aFolder.Equals("") ) + if(aJarSource.Equals("") || aFolder == nsnull ) { *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); return NS_OK; @@ -525,7 +536,7 @@ PRInt32 nsInstall::AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn) { @@ -541,7 +552,7 @@ nsInstall::AddSubcomponent(const nsString& aRegName, PRInt32 nsInstall::AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, - const nsString& aFolder, + nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn) { @@ -575,6 +586,11 @@ PRInt32 nsInstall::AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn) { + if(mPackageFolder == nsnull) + { + *aReturn = SaveError( nsInstall::PACKAGE_FOLDER_NOT_SET ); + return NS_OK; + } PRInt32 result = SanityCheck(); if (result != nsInstall::SUCCESS) @@ -583,12 +599,6 @@ nsInstall::AddSubcomponent(const nsString& aJarSource, return NS_OK; } - if(mPackageFolder.Equals("")) - { - *aReturn = SaveError( nsInstall::PACKAGE_FOLDER_NOT_SET ); - return NS_OK; - } - nsString version; *aReturn = mVersionInfo->ToString(version); @@ -605,8 +615,6 @@ nsInstall::AddSubcomponent(const nsString& aJarSource, "", PR_FALSE, aReturn); - - } PRInt32 @@ -648,7 +656,7 @@ nsInstall::DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn) } PRInt32 -nsInstall::DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn) +nsInstall::DeleteFile(nsInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn) { PRInt32 result = SanityCheck(); @@ -888,14 +896,18 @@ nsInstall::Gestalt(const nsString& aSelector, PRInt32* aReturn) } PRInt32 -nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder) +nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsInstallFolder** aNewFolder) { long err; char* componentCString; char dir[MAXREGPATHLEN]; nsFileSpec nsfsDir; - *aFolder = nsnull; + + if(!aNewFolder) + return INVALID_ARGUMENTS; + + *aNewFolder = nsnull; nsString tempString; @@ -935,12 +947,7 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS if(*dir != '\0') { - nsfsDir = dir; - if(aSubdirectory != "") - { - nsfsDir += aSubdirectory; - } - *aFolder = new nsString(nsfsDir.GetNativePathCString()); + *aNewFolder = new nsInstallFolder(dir, aSubdirectory); } if (componentCString) @@ -950,35 +957,53 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS } PRInt32 -nsInstall::GetComponentFolder(const nsString& aComponentName, nsString** aFolder) +nsInstall::GetComponentFolder(const nsString& aComponentName, nsInstallFolder** aNewFolder) { - return GetComponentFolder(aComponentName, "", aFolder); + return GetComponentFolder(aComponentName, "", aNewFolder); } -PRInt32 -nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory, nsString** aFolder) +PRInt32 +nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory, nsInstallFolder** aNewFolder) { - nsInstallFolder* spec = nsnull; - *aFolder = nsnull; + /* This version of GetFolder takes an nsString object as the first param */ + if (!aNewFolder) + return INVALID_ARGUMENTS; - spec = new nsInstallFolder(targetFolder, aSubdirectory); - - if (spec != nsnull) + *aNewFolder = new nsInstallFolder(targetFolder, aSubdirectory); + if (aNewFolder == nsnull) { - nsString dirString; - spec->GetDirectoryPath(dirString); - - *aFolder = new nsString(dirString); + return NS_ERROR_OUT_OF_MEMORY; } - return NS_OK; + + return NS_OK; } PRInt32 -nsInstall::GetFolder(const nsString& targetFolder, nsString** aFolder) +nsInstall::GetFolder(const nsString& targetFolder, nsInstallFolder** aNewFolder) { - return GetFolder(targetFolder, "", aFolder); + /* This version of GetFolder takes an nsString object as the only param */ + return GetFolder(targetFolder, "", aNewFolder); } +PRInt32 +nsInstall::GetFolder( nsInstallFolder& aTargetFolderObj, const nsString& aSubdirectory, nsInstallFolder** aNewFolder ) +{ + /* This version of GetFolder takes a nsInstallFolder object as the first param */ + if (!aNewFolder) + return INVALID_ARGUMENTS; + + *aNewFolder = new nsInstallFolder(aTargetFolderObj, aSubdirectory); + if (aNewFolder == nsnull) + { + return NS_ERROR_OUT_OF_MEMORY; + } + + return NS_OK; +} + + + + PRInt32 nsInstall::GetLastError(PRInt32* aReturn) { @@ -1199,7 +1224,7 @@ cleanup: } PRInt32 -nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) +nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn) { PRInt32 result = SanityCheck(); @@ -1249,7 +1274,7 @@ nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsStr } PRInt32 -nsInstall::Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) +nsInstall::Patch(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn) { return Patch(aRegName, "", aJarSource, aFolder, aTargetName, aReturn); } @@ -1262,9 +1287,10 @@ nsInstall::ResetError() } PRInt32 -nsInstall::SetPackageFolder(const nsString& aFolder) +nsInstall::SetPackageFolder(nsInstallFolder& aFolder) { - mPackageFolder = aFolder; + mPackageFolder = new nsInstallFolder(aFolder, ""); + return NS_OK; } @@ -1306,11 +1332,11 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis if(REGERR_OK == VR_GetDefaultDirectory(szRegPackageName, MAXREGPATHLEN, szRegPackagePath)) { - mPackageFolder = szRegPackagePath; + mPackageFolder = new nsInstallFolder(szRegPackagePath, ""); } else { - mPackageFolder.SetString(""); + mPackageFolder = nsnull; } if(szRegPackageName) @@ -2072,6 +2098,9 @@ nsInstall::CleanUp(void) delete mPatchList; } + if (mPackageFolder != nsnull) + delete (mPackageFolder); + mRegistryPackageName = ""; // used to see if StartInstall() has been called mStartInstallCompleted = PR_FALSE; } diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index 3192e984afc1..42d87a49f0e3 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -44,6 +44,7 @@ #include "nsInstallObject.h" #include "nsInstallVersion.h" +#include "nsInstallFolder.h" #include "nsIXPINotifier.h" @@ -56,6 +57,7 @@ #include "nsIEnumerator.h" #include "nsIZipReader.h" + class nsInstallInfo { public: @@ -181,35 +183,39 @@ class nsInstall PRInt32 AbortInstall(PRInt32 aErrorNumber); - PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); - PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); - PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn); PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn); - PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); - PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); - PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn); PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn); - PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); + PRInt32 DeleteFile(nsInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn); PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn); PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn); PRInt32 FinalizeInstall(PRInt32* aReturn); PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn); - PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder); - PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder); - PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder); - PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder); + + PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsInstallFolder** aFolder); + PRInt32 GetComponentFolder(const nsString& aComponentName, nsInstallFolder** aFolder); + + PRInt32 GetFolder(nsInstallFolder& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder); + PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder); + PRInt32 GetFolder(const nsString& aTargetFolder, nsInstallFolder** aFolder); + PRInt32 GetLastError(PRInt32* aReturn); PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn); PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn); PRInt32 LoadResources(JSContext* cx, const nsString& aBaseName, 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, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 ResetError(); - PRInt32 SetPackageFolder(const nsString& aFolder); + PRInt32 SetPackageFolder(nsInstallFolder& aFolder); PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn); PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn); @@ -264,13 +270,14 @@ class nsInstall JSObject* mWinRegObject; JSObject* mWinProfileObject; + nsFileSpec mJarFileLocation; nsIZipReader* mJarFileData; nsString mInstallArguments; nsString mInstallURL; - nsString mPackageFolder; + nsInstallFolder* mPackageFolder; PRBool mUserCancelled; PRBool mStatusSent; diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index fd6a3fc0d1c5..6f41bf65023e 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -36,14 +36,18 @@ #include "nsInstall.h" #include "nsIDOMInstallVersion.h" +MOZ_DECL_CTOR_COUNTER(nsInstallDelete); + nsInstallDelete::nsInstallDelete( nsInstall* inInstall, - const nsString& folderSpec, + nsInstallFolder* folderSpec, const nsString& inPartialPath, PRInt32 *error) : nsInstallObject(inInstall) { - if ((folderSpec.Equals("")) || (inInstall == NULL)) + MOZ_COUNT_CTOR(nsInstallDelete); + + if ((folderSpec == nsnull) || (inInstall == nsnull)) { *error = nsInstall::INVALID_ARGUMENTS; return; @@ -53,15 +57,20 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, mFinalFile = nsnull; mRegistryName = ""; + nsFileSpec* tmp = folderSpec->GetFileSpec(); + if (!tmp) + { + *error = nsInstall::INVALID_ARGUMENTS; + return; + } - mFinalFile = new nsFileSpec(folderSpec); - + mFinalFile = new nsFileSpec(*tmp); if (mFinalFile == nsnull) { *error = nsInstall::OUT_OF_MEMORY; return; } - + *mFinalFile += inPartialPath; *error = ProcessInstallDelete(); @@ -73,6 +82,8 @@ nsInstallDelete::nsInstallDelete( nsInstall* inInstall, : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallDelete); + if (inInstall == NULL) { *error = nsInstall::INVALID_ARGUMENTS; @@ -91,6 +102,8 @@ nsInstallDelete::~nsInstallDelete() { if (mFinalFile == nsnull) delete mFinalFile; + + MOZ_COUNT_DTOR(nsInstallDelete); } diff --git a/xpinstall/src/nsInstallDelete.h b/xpinstall/src/nsInstallDelete.h index 31032db45f47..6f6e5bd58eab 100644 --- a/xpinstall/src/nsInstallDelete.h +++ b/xpinstall/src/nsInstallDelete.h @@ -42,7 +42,7 @@ class nsInstallDelete : public nsInstallObject public: nsInstallDelete( nsInstall* inInstall, - const nsString& folderSpec, + nsInstallFolder* folderSpec, const nsString& inPartialPath, PRInt32 *error); diff --git a/xpinstall/src/nsInstallExecute.cpp b/xpinstall/src/nsInstallExecute.cpp index 4c2420654398..9bf6771be1ba 100644 --- a/xpinstall/src/nsInstallExecute.cpp +++ b/xpinstall/src/nsInstallExecute.cpp @@ -37,6 +37,8 @@ #include "nsInstall.h" #include "nsIDOMInstallVersion.h" +MOZ_DECL_CTOR_COUNTER(nsInstallExecute); + nsInstallExecute:: nsInstallExecute( nsInstall* inInstall, const nsString& inJarLocation, const nsString& inArgs, @@ -44,6 +46,8 @@ nsInstallExecute:: nsInstallExecute( nsInstall* inInstall, : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallExecute); + if ((inInstall == nsnull) || (inJarLocation.Equals("")) ) { *error = nsInstall::INVALID_ARGUMENTS; @@ -61,6 +65,8 @@ nsInstallExecute::~nsInstallExecute() { if (mExecutableFile) delete mExecutableFile; + + MOZ_COUNT_DTOR(nsInstallExecute); } diff --git a/xpinstall/src/nsInstallFile.cpp b/xpinstall/src/nsInstallFile.cpp index 909c05d5fbd9..84c5674e0244 100644 --- a/xpinstall/src/nsInstallFile.cpp +++ b/xpinstall/src/nsInstallFile.cpp @@ -41,17 +41,20 @@ inFinalFileSpec - final location on disk */ +MOZ_DECL_CTOR_COUNTER(nsInstallFile); nsInstallFile::nsInstallFile(nsInstall* inInstall, const nsString& inComponentName, const nsString& inVInfo, const nsString& inJarLocation, - const nsString& folderSpec, + nsInstallFolder *folderSpec, const nsString& inPartialPath, PRBool forceInstall, PRInt32 *error) : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallFile); + mVersionRegistryName = nsnull; mJarLocation = nsnull; mExtracedFile = nsnull; @@ -60,7 +63,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, mUpgradeFile = PR_FALSE; - if ((folderSpec.Equals("")) || (inInstall == NULL)) + if ((folderSpec == nsnull) || (inInstall == NULL)) { *error = nsInstall::INVALID_ARGUMENTS; return; @@ -122,14 +125,20 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, Recycle(qualifiedRegNameString); - mFinalFile = new nsFileSpec(folderSpec); - + nsFileSpec* tmp = folderSpec->GetFileSpec(); + if (!tmp) + { + *error = nsInstall::INVALID_ARGUMENTS; + return; + } + + mFinalFile = new nsFileSpec(*tmp); if (mFinalFile == nsnull) { *error = nsInstall::OUT_OF_MEMORY; return; } - + if ( mFinalFile->Exists() ) { // is there a file with the same name as the proposed folder? @@ -222,6 +231,8 @@ nsInstallFile::~nsInstallFile() if (mVersionInfo) delete mVersionInfo; + + MOZ_COUNT_DTOR(nsInstallFile); } /* Prepare diff --git a/xpinstall/src/nsInstallFile.h b/xpinstall/src/nsInstallFile.h index 7d5afa11f8c0..0188e9bd3274 100644 --- a/xpinstall/src/nsInstallFile.h +++ b/xpinstall/src/nsInstallFile.h @@ -53,7 +53,7 @@ class nsInstallFile : public nsInstallObject const nsString& inVRName, const nsString& inVInfo, const nsString& inJarLocation, - const nsString& folderSpec, + nsInstallFolder *folderSpec, const nsString& inPartialPath, PRBool forceInstall, PRInt32 *error); diff --git a/xpinstall/src/nsInstallFileOpItem.cpp b/xpinstall/src/nsInstallFileOpItem.cpp index 30e0ce26c28f..1b509df2e799 100644 --- a/xpinstall/src/nsInstallFileOpItem.cpp +++ b/xpinstall/src/nsInstallFileOpItem.cpp @@ -39,6 +39,8 @@ /* Public Methods */ +MOZ_DECL_CTOR_COUNTER(nsInstallFileOpItem); + nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32 aCommand, nsFileSpec& aTarget, @@ -46,18 +48,20 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - *aReturn = nsInstall::SUCCESS; - mIObj = aInstallObj; - mCommand = aCommand; - mFlags = aFlags; - mSrc = nsnull; - mParams = nsnull; - mStrTarget = nsnull; + MOZ_COUNT_CTOR(nsInstallFileOpItem); - mTarget = new nsFileSpec(aTarget); - - if(mTarget == nsnull) - *aReturn = nsInstall::OUT_OF_MEMORY; + *aReturn = nsInstall::SUCCESS; + mIObj = aInstallObj; + mCommand = aCommand; + mFlags = aFlags; + mSrc = nsnull; + mParams = nsnull; + mStrTarget = nsnull; + + mTarget = new nsFileSpec(aTarget); + + if(mTarget == nsnull) + *aReturn = nsInstall::OUT_OF_MEMORY; } nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, @@ -67,17 +71,19 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - *aReturn = nsInstall::SUCCESS; + MOZ_COUNT_CTOR(nsInstallFileOpItem); + + *aReturn = nsInstall::SUCCESS; mIObj = aInstallObj; - mCommand = aCommand; - mFlags = 0; - mParams = nsnull; - mStrTarget = nsnull; + mCommand = aCommand; + mFlags = 0; + mParams = nsnull; + mStrTarget = nsnull; mAction = ACTION_NONE; - + mSrc = new nsFileSpec(aSrc); mTarget = new nsFileSpec(aTarget); - + if(mTarget == nsnull || mSrc == nsnull) *aReturn = nsInstall::OUT_OF_MEMORY; } @@ -88,7 +94,9 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - *aReturn = nsInstall::SUCCESS; + MOZ_COUNT_CTOR(nsInstallFileOpItem); + + *aReturn = nsInstall::SUCCESS; mIObj = aInstallObj; mCommand = aCommand; mFlags = 0; @@ -111,30 +119,32 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { + MOZ_COUNT_CTOR(nsInstallFileOpItem); + *aReturn = nsInstall::SUCCESS; mIObj = aInstallObj; - mCommand = aCommand; - mFlags = 0; + mCommand = aCommand; + mFlags = 0; mAction = ACTION_NONE; switch(mCommand) { case NS_FOP_DIR_RENAME: case NS_FOP_FILE_RENAME: - mSrc = new nsFileSpec(a1); - mTarget = nsnull; + mSrc = new nsFileSpec(a1); + mTarget = nsnull; mParams = nsnull; mStrTarget = new nsString(a2); - + if (mSrc == nsnull || mStrTarget == nsnull) *aReturn = nsInstall::OUT_OF_MEMORY; - + break; case NS_FOP_FILE_EXECUTE: default: - mSrc = nsnull; - mTarget = new nsFileSpec(a1); + mSrc = nsnull; + mTarget = new nsFileSpec(a1); mParams = new nsString(a2); mStrTarget = nsnull; @@ -156,7 +166,9 @@ nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj, PRInt32* aReturn) :nsInstallObject(aInstallObj) { - *aReturn = nsInstall::SUCCESS; + MOZ_COUNT_CTOR(nsInstallFileOpItem); + + *aReturn = nsInstall::SUCCESS; mIObj = aInstallObj; mCommand = aCommand; mIconId = aIconId; @@ -208,6 +220,8 @@ nsInstallFileOpItem::~nsInstallFileOpItem() delete mWorkingPath; if(mIcon) delete mIcon; + + MOZ_COUNT_DTOR(nsInstallFileOpItem); } #ifdef XP_MAC diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index b779a0fcb928..02e5a8dc5b86 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -82,15 +82,17 @@ struct DirectoryTable DirectoryTable[] = }; +MOZ_DECL_CTOR_COUNTER(nsInstallFolder); nsInstallFolder::nsInstallFolder(const nsString& aFolderID) { - mFileSpec = nsnull; - SetDirectoryPath( aFolderID, ""); + nsInstallFolder( aFolderID, "" ); } nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath) { + MOZ_COUNT_CTOR(nsInstallFolder); + mFileSpec = nsnull; /* @@ -132,12 +134,29 @@ nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRel } +nsInstallFolder::nsInstallFolder(nsInstallFolder& inFolder, const nsString& subString) +{ + MOZ_COUNT_CTOR(nsInstallFolder); + + mFileSpec = new nsFileSpec(); + if (mFileSpec != nsnull) + { + *mFileSpec = *inFolder.mFileSpec; + + if (subString != "") + *mFileSpec += subString; + } +} + + nsInstallFolder::~nsInstallFolder() { if (mFileSpec != nsnull) delete mFileSpec; + + MOZ_COUNT_DTOR(nsInstallFolder); } - + void nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath) { @@ -166,6 +185,8 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe } else if ( aFolderID.EqualsIgnoreCase("Installed") ) { + // XXX block from users or remove "Installed" + // XXX the filespec creation will fail due to unix slashes on Mac mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path. return; } @@ -426,3 +447,21 @@ nsInstallFolder::SetAppShellDirectory(PRUint32 value) NS_RELEASE(fs); } } + +nsFileSpec* +nsInstallFolder::GetFileSpec() +{ + if (mFileSpec == nsnull) + return nsnull; + return mFileSpec; +} + +PRInt32 +nsInstallFolder::ToString(nsAutoString* outString) +{ + //XXX: May need to fix. Native charset paths will be converted into Unicode when the get to JS + // This will appear to work on Latin-1 charsets but won't work on Mac or other charsets. + + *outString = mFileSpec->GetCString(); + return NS_OK; +} diff --git a/xpinstall/src/nsInstallFolder.h b/xpinstall/src/nsInstallFolder.h index ffe32af9f4a3..a61781f74b55 100644 --- a/xpinstall/src/nsInstallFolder.h +++ b/xpinstall/src/nsInstallFolder.h @@ -39,16 +39,19 @@ class nsInstallFolder public: nsInstallFolder(const nsString& aFolderID); + nsInstallFolder(nsInstallFolder& inFolder, const nsString& subString); nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath); virtual ~nsInstallFolder(); void GetDirectoryPath(nsString& aDirectoryPath); + nsFileSpec* GetFileSpec(); + PRInt32 ToString(nsAutoString* outString); private: nsFileSpec* mFileSpec; - void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath); + void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath); void PickDefaultDirectory(); PRInt32 MapNameToEnum(const nsString& name); void SetAppShellDirectory(PRUint32 value); diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 54dfc7f8fe14..8b9fcc910a19 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -65,6 +65,7 @@ static int32 gdiff_validateFile( pDIFFDATA dd, int file ); static PRBool su_unbind(char* oldsrc, char* newsrc); #endif +MOZ_DECL_CTOR_COUNTER(nsInstallPatch); nsInstallPatch::nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, @@ -74,6 +75,8 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallPatch); + char tempTargetFile[MAXREGPATHLEN]; char* tempVersionString = inVRName.ToNewCString(); @@ -113,25 +116,34 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, const nsString& inVRName, const nsString& inVInfo, const nsString& inJarLocation, - const nsString& folderSpec, + nsInstallFolder* folderSpec, const nsString& inPartialPath, PRInt32 *error) : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallPatch); + if ((inInstall == nsnull) || (inVRName.Equals("")) || (inJarLocation.Equals(""))) { *error = nsInstall::INVALID_ARGUMENTS; return; } + nsFileSpec* tmp = folderSpec->GetFileSpec(); + if (!tmp) + { + *error = nsInstall::INVALID_ARGUMENTS; + return; + } + mPatchFile = nsnull; mTargetFile = nsnull; mPatchedFile = nsnull; mRegistryName = new nsString(inVRName); mJarLocation = new nsString(inJarLocation); mVersionInfo = new nsInstallVersion(); - mTargetFile = new nsFileSpec(folderSpec); + mTargetFile = new nsFileSpec(*tmp); if (mRegistryName == nsnull || mJarLocation == nsnull || @@ -169,6 +181,7 @@ nsInstallPatch::~nsInstallPatch() if (mPatchFile) delete mPatchFile; + MOZ_COUNT_DTOR(nsInstallPatch); } diff --git a/xpinstall/src/nsInstallPatch.h b/xpinstall/src/nsInstallPatch.h index 3018223d6fbd..a6abf19cdce6 100644 --- a/xpinstall/src/nsInstallPatch.h +++ b/xpinstall/src/nsInstallPatch.h @@ -41,7 +41,7 @@ class nsInstallPatch : public nsInstallObject const nsString& inVRName, const nsString& inVInfo, const nsString& inJarLocation, - const nsString& folderSpec, + nsInstallFolder* folderSpec, const nsString& inPartialPath, PRInt32 *error); diff --git a/xpinstall/src/nsInstallUninstall.cpp b/xpinstall/src/nsInstallUninstall.cpp index 071b99e2789f..0b297fad2b87 100644 --- a/xpinstall/src/nsInstallUninstall.cpp +++ b/xpinstall/src/nsInstallUninstall.cpp @@ -34,6 +34,7 @@ extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName); REGERR su_UninstallProcessItem(char *component_path); +MOZ_DECL_CTOR_COUNTER(nsInstallUninstall); nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall, const nsString& regName, @@ -41,6 +42,8 @@ nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall, : nsInstallObject(inInstall) { + MOZ_COUNT_CTOR(nsInstallUninstall); + if (regName.Equals("")) { *error = nsInstall::INVALID_ARGUMENTS; @@ -67,6 +70,7 @@ nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall, nsInstallUninstall::~nsInstallUninstall() { + MOZ_COUNT_CTOR(nsInstallUninstall); } diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index 9159d86b9d4a..c18f0c20cf4e 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -40,6 +40,9 @@ extern JSClass WinRegClass; extern JSClass WinProfileClass; #endif +#include "nsJSFileSpecObj.h" +extern JSClass FileSpecObjectClass; + // // Install property ids // @@ -57,6 +60,9 @@ enum Install_slots INSTALL_INSTALLED_FILES = -10 }; +// prototype for filespec objects +JSObject *gFileSpecProto = nsnull; + /***********************************************************************/ // // Install Properties Getter @@ -369,6 +375,8 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval nsAutoString b2; nsAutoString b3; nsAutoString b4; + JSObject *jsObj; + nsInstallFolder *folder; PRBool b5; *rval = JSVAL_NULL; @@ -400,10 +408,18 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); + jsObj = JSVAL_TO_OBJECT(argv[2]); - if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddDirectory(b0, b1, folder, b3, &nativeRet)) { return JS_FALSE; } @@ -421,10 +437,18 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval ConvertJSValToStr(b0, cx, argv[0]); ConvertJSvalToVersionString(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); ConvertJSValToStr(b4, cx, argv[4]); + jsObj = JSVAL_TO_OBJECT(argv[3]); + + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } - if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, &nativeRet)) + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, folder, b4, &nativeRet)) { return JS_FALSE; } @@ -444,7 +468,7 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval ConvertJSValToStr(b0, cx, argv[0]); ConvertJSvalToVersionString(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); + jsObj = JSVAL_TO_OBJECT(argv[3]); ConvertJSValToStr(b4, cx, argv[4]); if(!ConvertJSValToBool(&b5, cx, argv[5])) @@ -452,7 +476,15 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_FALSE; } - if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, b5, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, folder, b4, b5, &nativeRet)) { return JS_FALSE; } @@ -482,6 +514,8 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js nsAutoString b2; nsAutoString b3; nsAutoString b4; + JSObject* jsObj; + nsInstallFolder* folder; PRBool b5; *rval = JSVAL_NULL; @@ -503,7 +537,7 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js ConvertJSValToStr(b0, cx, argv[0]); ConvertJSvalToVersionString(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); + jsObj = JSVAL_TO_OBJECT(argv[3]); ConvertJSValToStr(b4, cx, argv[4]); if(!ConvertJSValToBool(&b5, cx, argv[5])) @@ -511,7 +545,15 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js return JS_FALSE; } - if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, b5, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "AddSubcomponent:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, folder, b4, b5, &nativeRet)) { return JS_FALSE; } @@ -529,10 +571,18 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js ConvertJSValToStr(b0, cx, argv[0]); ConvertJSvalToVersionString(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); ConvertJSValToStr(b4, cx, argv[4]); + jsObj = JSVAL_TO_OBJECT(argv[3]); - if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "AddSubcomponent:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, folder, b4, &nativeRet)) { return JS_FALSE; } @@ -548,10 +598,18 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); + jsObj = JSVAL_TO_OBJECT(argv[2]); - if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, folder, b3, &nativeRet)) { return JS_FALSE; } @@ -629,8 +687,9 @@ InstallDeleteFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); PRInt32 nativeRet; - nsAutoString b0; + JSObject* jsObj; nsAutoString b1; + nsInstallFolder* folder; *rval = JSVAL_NULL; @@ -644,10 +703,18 @@ InstallDeleteFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * // public int DeleteFile ( Object folder, // String relativeFileName); - ConvertJSValToStr(b0, cx, argv[0]); + jsObj = JSVAL_TO_OBJECT(argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - if(NS_OK != nativeThis->DeleteFile(b0, b1, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "DeleteFile:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->DeleteFile(folder, b1, &nativeRet)) { return JS_FALSE; } @@ -849,7 +916,7 @@ PR_STATIC_CALLBACK(JSBool) InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - nsString* nativeRet; + nsInstallFolder* folder; nsAutoString b0; nsAutoString b1; @@ -864,19 +931,16 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, { // public int GetComponentFolder ( String registryName, // String subDirectory); - - ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - - if(NS_OK != nativeThis->GetComponentFolder(b0, b1, &nativeRet)) + if(JSVAL_IS_STRING(argv[0])) // check if the first argument is a string { - return JS_FALSE; + ConvertJSValToStr(b0, cx, argv[0]); + if(NS_OK != nativeThis->GetComponentFolder(b0, b1, &folder)) + return JS_FALSE; } - if(nsnull == nativeRet) - *rval = JSVAL_NULL; - else - ConvertStrToJSVal(*nativeRet, cx, rval); + if(nsnull != folder) + return JS_FALSE; } else if(argc >= 1) { @@ -884,15 +948,13 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, ConvertJSValToStr(b0, cx, argv[0]); - if(NS_OK != nativeThis->GetComponentFolder(b0, &nativeRet)) + if(NS_OK != nativeThis->GetComponentFolder(b0, &folder)) { return JS_FALSE; } - if(nsnull == nativeRet) - *rval = JSVAL_NULL; - else - ConvertStrToJSVal(*nativeRet, cx, rval); + if(nsnull != folder) + return JS_FALSE; } else { @@ -900,6 +962,19 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_FALSE; } + /* Now create the new JSObject */ + JSObject* fileSpecObject; + + fileSpecObject = JS_NewObject(cx, &FileSpecObjectClass, gFileSpecProto, NULL); + if (fileSpecObject == NULL) + return JS_FALSE; + + JS_SetPrivate(cx, fileSpecObject, folder); + if (fileSpecObject == NULL) + return JS_FALSE; + + *rval = OBJECT_TO_JSVAL(fileSpecObject); + return JS_TRUE; } @@ -911,9 +986,10 @@ PR_STATIC_CALLBACK(JSBool) InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - nsString* nativeRet; + JSObject *jsObj; nsAutoString b0; nsAutoString b1; + nsInstallFolder *folder = nsnull; *rval = JSVAL_NULL; @@ -924,21 +1000,35 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r if(argc >= 2) { - // public int GetFolder ( String folderName, --OR-- Object localDirSpec, - // String subDirectory); - - ConvertJSValToStr(b0, cx, argv[0]); - ConvertJSValToStr(b1, cx, argv[1]); - - if(NS_OK != nativeThis->GetFolder(b0, b1, &nativeRet)) + ConvertJSValToStr(b1, cx, argv[1]); // we know that the second param must be a string + if(JSVAL_IS_STRING(argv[0])) // check if the first argument is a string { - return JS_FALSE; + ConvertJSValToStr(b0, cx, argv[0]); + if(NS_OK != nativeThis->GetFolder(b0, b1, &folder)) + return JS_FALSE; + } + else /* it must be an object */ + { + jsObj = JSVAL_TO_OBJECT(argv[0]); + + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + if (!folder) + { + JS_ReportError(cx, "GetFolder:Invalid Parameter"); + return JS_FALSE; + } + else if(NS_OK != nativeThis->GetFolder(*folder, b1, &folder)) + return JS_FALSE; } - if(nsnull == nativeRet) - *rval = JSVAL_NULL; - else - ConvertStrToJSVal(*nativeRet, cx, rval); + if(nsnull == folder) + return JS_FALSE; } else if(argc >= 1) { @@ -946,26 +1036,42 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r ConvertJSValToStr(b0, cx, argv[0]); - if(NS_OK != nativeThis->GetFolder(b0, &nativeRet)) + if(NS_OK != nativeThis->GetFolder(b0, &folder)) { return JS_FALSE; } - if(nsnull == nativeRet) - *rval = JSVAL_NULL; - else - ConvertStrToJSVal(*nativeRet, cx, rval); + if(nsnull == folder) + return JS_FALSE; } else { - JS_ReportError(cx, "Function GetFolder requires 2 parameters"); + JS_ReportError(cx, "Function GetFolder requires at least 1 parameter"); return JS_FALSE; } - return JS_TRUE; + if ( folder ) + { + /* Now create the new JSObject */ + JSObject* fileSpecObject; + + fileSpecObject = JS_NewObject(cx, &FileSpecObjectClass, gFileSpecProto, NULL); + if (fileSpecObject == NULL) + return JS_FALSE; + + JS_SetPrivate(cx, fileSpecObject, folder); + if (fileSpecObject == NULL) + return JS_FALSE; + + *rval = OBJECT_TO_JSVAL(fileSpecObject); + } + + + return JS_TRUE; } + // // Native method GetLastError // @@ -1132,6 +1238,11 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) nsAutoString b3; nsAutoString b4; + JSObject *jsObj; + + nsInstallFolder *folder = nsnull; + + *rval = JSVAL_NULL; // If there's no private data, this must be the prototype, so ignore @@ -1150,10 +1261,15 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) ConvertJSValToStr(b0, cx, argv[0]); ConvertJSvalToVersionString(b1, cx, argv[1]); ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); - ConvertJSValToStr(b4, cx, argv[4]); + ConvertJSValToStr(b3, cx, argv[4]); + jsObj = JSVAL_TO_OBJECT(argv[3]); - if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, b4, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + return JS_FALSE; // Do we return an error message to the console here? + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->Patch(b0, b1, b2, folder, b3, &nativeRet)) { return JS_FALSE; } @@ -1169,10 +1285,15 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) ConvertJSValToStr(b0, cx, argv[0]); ConvertJSValToStr(b1, cx, argv[1]); - ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); + ConvertJSValToStr(b2, cx, argv[3]); + jsObj = JSVAL_TO_OBJECT(argv[2]); - if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, &nativeRet)) + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) + return JS_FALSE; // Do we return an error message to the console here? + + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + + if(NS_OK != nativeThis->Patch(b0, b1, folder, b2, &nativeRet)) { return JS_FALSE; } @@ -1233,7 +1354,8 @@ InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); nsAutoString b0; - + JSObject *jsObj; + nsInstallFolder *folder; *rval = JSVAL_NULL; // If there's no private data, this must be the prototype, so ignore @@ -1245,13 +1367,23 @@ InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j { // public int SetPackageFolder (Object folder); - ConvertJSValToStr(b0, cx, argv[0]); - - if(NS_OK != nativeThis->SetPackageFolder(b0)) + jsObj = JSVAL_TO_OBJECT(argv[0]); + if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, argv)) { - return JS_FALSE; + JS_ReportError(cx, "setPackageFolder:Invalid Parameter"); + return JS_FALSE; } + folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj); + if (!folder) + { + JS_ReportError(cx, "setPackageFolder:Invalid Parameter"); + return JS_FALSE; + } + else + if(NS_OK != nativeThis->SetPackageFolder(*folder)) + return JS_FALSE; + *rval = JSVAL_VOID; } else @@ -2732,6 +2864,11 @@ JSObject * InitXPInstallObjects(JSContext *jscontext, } nativeInstallObject->SaveWinProfilePrototype(winProfilePrototype); #endif - + + if(NS_OK != InitFileSpecObjectPrototype(jscontext, global, &gFileSpecProto)) + { + return nsnull; + } + return installObject; } diff --git a/xpinstall/src/nsLoggingProgressNotifier.cpp b/xpinstall/src/nsLoggingProgressNotifier.cpp index 6d2750ce225c..049900072a08 100644 --- a/xpinstall/src/nsLoggingProgressNotifier.cpp +++ b/xpinstall/src/nsLoggingProgressNotifier.cpp @@ -36,15 +36,16 @@ nsLoggingProgressNotifier::nsLoggingProgressNotifier() + : mLogStream(0) { - NS_INIT_REFCNT(); + NS_INIT_ISUPPORTS(); } nsLoggingProgressNotifier::~nsLoggingProgressNotifier() { if (mLogStream) { - NS_ASSERTION(PR_FALSE, "We're being destroyed before script finishes!"); + NS_WARN_IF_FALSE(PR_FALSE, "We're being destroyed before script finishes!"); mLogStream->close(); delete mLogStream; mLogStream = 0; diff --git a/xpinstall/src/nsSoftwareUpdate.cpp b/xpinstall/src/nsSoftwareUpdate.cpp index a3e7da2fb8c3..f19336d8a97e 100644 --- a/xpinstall/src/nsSoftwareUpdate.cpp +++ b/xpinstall/src/nsSoftwareUpdate.cpp @@ -117,15 +117,15 @@ nsSoftwareUpdate::nsSoftwareUpdate() /***************************************/ /* Add us to the Javascript Name Space */ /***************************************/ - - new nsSoftwareUpdateNameSet(); - + + RegisterNameset(); + /***************************************/ /* Register us with NetLib */ /***************************************/ // FIX - - + + /***************************************/ /* Startup the Version Registry */ /***************************************/ @@ -157,7 +157,7 @@ nsSoftwareUpdate::nsSoftwareUpdate() /***************************************/ nsLoggingProgressNotifier *logger = new nsLoggingProgressNotifier(); - RegisterNotifier(logger); + RegisterNotifier(logger); // XXX [MLK] memory leak } @@ -364,6 +364,24 @@ nsSoftwareUpdate::RunNextInstall() } +nsresult +nsSoftwareUpdate::RegisterNameset() +{ + nsresult rv; + nsCOMPtr namesetService = + do_GetService( kCScriptNameSetRegistryCID, &rv ); + + if (NS_SUCCEEDED(rv)) + { + nsSoftwareUpdateNameSet* nameset = new nsSoftwareUpdateNameSet(); + // the NameSet service will AddRef this one + namesetService->AddExternalNameSet( nameset ); + } + + return rv; +} + + NS_IMETHODIMP nsSoftwareUpdate::SetProgramDirectory(nsIFileSpec *aDir) { @@ -398,17 +416,7 @@ nsSoftwareUpdate::SetProgramDirectory(nsIFileSpec *aDir) nsSoftwareUpdateNameSet::nsSoftwareUpdateNameSet() { - NS_INIT_REFCNT(); - - nsIScriptNameSetRegistry *scriptNameSet; - nsresult result = nsServiceManager::GetService(kCScriptNameSetRegistryCID, - kIScriptNameSetRegistryIID, - (nsISupports **)&scriptNameSet); - if (NS_SUCCEEDED(result)) - { - scriptNameSet->AddExternalNameSet(this); - } - + NS_INIT_ISUPPORTS(); } nsSoftwareUpdateNameSet::~nsSoftwareUpdateNameSet() diff --git a/xpinstall/src/nsSoftwareUpdate.h b/xpinstall/src/nsSoftwareUpdate.h index 3ea0e4bf30ee..88d767b0b2a5 100644 --- a/xpinstall/src/nsSoftwareUpdate.h +++ b/xpinstall/src/nsSoftwareUpdate.h @@ -67,7 +67,7 @@ class nsSoftwareUpdate: public nsIAppShellComponent, static nsIFileSpec* mProgramDir; nsresult RunNextInstall(); - nsresult DeleteScheduledNodes(); + nsresult RegisterNameset(); PRLock* mLock; PRBool mInstalling; @@ -83,8 +83,11 @@ class nsSoftwareUpdateNameSet : public nsIScriptExternalNameSet nsSoftwareUpdateNameSet(); virtual ~nsSoftwareUpdateNameSet(); + // nsISupports NS_DECL_ISUPPORTS - NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext); - NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); + + // nsIScriptExternalNameSet + NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext); + NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); }; #endif diff --git a/xpinstall/src/nsTopProgressNotifier.cpp b/xpinstall/src/nsTopProgressNotifier.cpp index 2a0871f50719..4b65b805ba42 100644 --- a/xpinstall/src/nsTopProgressNotifier.cpp +++ b/xpinstall/src/nsTopProgressNotifier.cpp @@ -41,7 +41,7 @@ nsTopProgressNotifier::~nsTopProgressNotifier() for (; i < mNotifiers->Count(); i++) { nsIXPINotifier* element = (nsIXPINotifier*)mNotifiers->ElementAt(i); - delete element; + NS_IF_RELEASE(element); } mNotifiers->Clear(); diff --git a/xpinstall/src/nsTopProgressNotifier.h b/xpinstall/src/nsTopProgressNotifier.h index 522ba9f0e2a6..cb30a83afbd7 100644 --- a/xpinstall/src/nsTopProgressNotifier.h +++ b/xpinstall/src/nsTopProgressNotifier.h @@ -26,6 +26,7 @@ #ifndef nsTopProgressNotifier_h__ #define nsTopProgressNotifier_h__ +#include "nsCOMPtr.h" #include "nsIXPINotifier.h" #include "nsVoidArray.h" @@ -49,7 +50,7 @@ class nsTopProgressNotifier : public nsIXPINotifier private: nsVoidArray *mNotifiers; - nsIXPINotifier *mActive; + nsCOMPtr mActive; }; diff --git a/xpinstall/src/nsWinProfile.cpp b/xpinstall/src/nsWinProfile.cpp index 8913af2d3033..15a098e96436 100644 --- a/xpinstall/src/nsWinProfile.cpp +++ b/xpinstall/src/nsWinProfile.cpp @@ -27,8 +27,12 @@ /* Public Methods */ +MOZ_DECL_CTOR_COUNTER(nsWinProfile); + nsWinProfile::nsWinProfile( nsInstall* suObj, const nsString& folder, const nsString& file ) { + MOZ_COUNT_CTOR(nsWinProfile); + mFilename = new nsString(folder); if (mFilename) @@ -47,6 +51,9 @@ nsWinProfile::~nsWinProfile() { if (mFilename) delete mFilename; + + MOZ_COUNT_DTOR(nsWinProfile); + } PRInt32 diff --git a/xpinstall/src/nsWinProfileItem.cpp b/xpinstall/src/nsWinProfileItem.cpp index 1c253fce9027..c967855b4393 100644 --- a/xpinstall/src/nsWinProfileItem.cpp +++ b/xpinstall/src/nsWinProfileItem.cpp @@ -27,12 +27,16 @@ /* Public Methods */ +MOZ_DECL_CTOR_COUNTER(nsWinProfileItem); + nsWinProfileItem::nsWinProfileItem(nsWinProfile* profileObj, nsString sectionName, nsString keyName, nsString val, PRInt32 *aReturn) : nsInstallObject(profileObj->InstallObject()) { + MOZ_COUNT_CTOR(nsWinProfileItem); + mProfile = profileObj; mSection = new nsString(sectionName); mKey = new nsString(keyName); @@ -53,6 +57,8 @@ nsWinProfileItem::~nsWinProfileItem() if (mSection) delete mSection; if (mKey) delete mKey; if (mValue) delete mValue; + + MOZ_COUNT_DTOR(nsWinProfileItem); } PRInt32 nsWinProfileItem::Complete() diff --git a/xpinstall/src/nsWinReg.cpp b/xpinstall/src/nsWinReg.cpp index 2a7757501092..bc9336e790c5 100644 --- a/xpinstall/src/nsWinReg.cpp +++ b/xpinstall/src/nsWinReg.cpp @@ -26,12 +26,21 @@ /* Public Methods */ +MOZ_DECL_CTOR_COUNTER(nsWinReg); + nsWinReg::nsWinReg(nsInstall* suObj) { - mInstallObject = suObj; + MOZ_COUNT_CTOR(nsWinReg); + + mInstallObject = suObj; mRootKey = (PRInt32)HKEY_CLASSES_ROOT; } +nsWinReg::~nsWinReg() +{ + MOZ_COUNT_CTOR(nsWinReg); +} + PRInt32 nsWinReg::SetRootKey(PRInt32 key) { diff --git a/xpinstall/src/nsWinReg.h b/xpinstall/src/nsWinReg.h index 9dd036853bcc..1370b38caa07 100644 --- a/xpinstall/src/nsWinReg.h +++ b/xpinstall/src/nsWinReg.h @@ -61,6 +61,7 @@ class nsWinReg /* Public Methods */ nsWinReg(nsInstall* suObj); + ~nsWinReg(); PRInt32 SetRootKey(PRInt32 key); PRInt32 CreateKey(const nsString& subkey, const nsString& classname, PRInt32* aReturn); diff --git a/xpinstall/src/nsWinRegItem.cpp b/xpinstall/src/nsWinRegItem.cpp index 6248326cc3dd..98d954dfc73d 100644 --- a/xpinstall/src/nsWinRegItem.cpp +++ b/xpinstall/src/nsWinRegItem.cpp @@ -29,10 +29,14 @@ /* Public Methods */ +MOZ_DECL_CTOR_COUNTER(nsWinRegItem); + nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsString& sub, const nsString& valname, const nsString& val, PRInt32 *aReturn) : nsInstallObject(regObj->InstallObject()) { - mReg = regObj; + MOZ_COUNT_CTOR(nsWinRegItem); + + mReg = regObj; mCommand = action; mRootkey = root; @@ -54,6 +58,8 @@ nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsString& sub, const nsString& valname, PRInt32 val, PRInt32 *aReturn) : nsInstallObject(regObj->InstallObject()) { + MOZ_COUNT_CTOR(nsWinRegItem); + mReg = regObj; mCommand = action; mRootkey = root; @@ -78,6 +84,7 @@ nsWinRegItem::~nsWinRegItem() if (mSubkey) delete mSubkey; if (mName) delete mName; if (mValue) delete mValue; + MOZ_COUNT_DTOR(nsWinRegItem); } PRInt32 nsWinRegItem::Complete() diff --git a/xpinstall/src/nsXPITriggerInfo.cpp b/xpinstall/src/nsXPITriggerInfo.cpp index ee2363340e42..2a463f2cd98b 100644 --- a/xpinstall/src/nsXPITriggerInfo.cpp +++ b/xpinstall/src/nsXPITriggerInfo.cpp @@ -34,12 +34,15 @@ static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); // // nsXPITriggerItem // +MOZ_DECL_CTOR_COUNTER(nsXPITriggerItem); nsXPITriggerItem::nsXPITriggerItem( const PRUnichar* aName, const PRUnichar* aURL, PRInt32 aFlags ) : mName(aName), mFlags(aFlags) { + MOZ_COUNT_CTOR(nsXPITriggerItem); + nsString URL(aURL); PRInt32 pos = URL.FindChar('?'); @@ -55,14 +58,23 @@ nsXPITriggerItem::nsXPITriggerItem( const PRUnichar* aName, } } +nsXPITriggerItem::~nsXPITriggerItem() +{ + MOZ_COUNT_DTOR(nsXPITriggerItem); +} + // // nsXPITriggerInfo // +MOZ_DECL_CTOR_COUNTER(nsXPITriggerInfo); + nsXPITriggerInfo::nsXPITriggerInfo() : mCx(0), mGlobal(JSVAL_NULL), mCbval(JSVAL_NULL) -{} +{ + MOZ_COUNT_CTOR(nsXPITriggerInfo); +} nsXPITriggerInfo::~nsXPITriggerInfo() { @@ -81,6 +93,8 @@ nsXPITriggerInfo::~nsXPITriggerInfo() if ( mCx && !JSVAL_IS_NULL(mCbval) ) JS_RemoveRoot( mCx, &mCbval ); + + MOZ_COUNT_DTOR(nsXPITriggerInfo); } void nsXPITriggerInfo::SaveCallback( JSContext *aCx, jsval aVal ) diff --git a/xpinstall/src/nsXPITriggerInfo.h b/xpinstall/src/nsXPITriggerInfo.h index f94468b99055..38cbdba980a2 100644 --- a/xpinstall/src/nsXPITriggerInfo.h +++ b/xpinstall/src/nsXPITriggerInfo.h @@ -52,6 +52,7 @@ class nsXPITriggerItem { public: nsXPITriggerItem( const PRUnichar* name, const PRUnichar* URL, PRInt32 flags = 0); + ~nsXPITriggerItem(); nsString mName; nsString mURL; @@ -74,7 +75,7 @@ class nsXPITriggerInfo { public: nsXPITriggerInfo(); - virtual ~nsXPITriggerInfo(); + ~nsXPITriggerInfo(); void Add( nsXPITriggerItem *aItem ) { if ( aItem ) mItems.AppendElement( (void*)aItem ); }