From 64d77c0aef0e36a5294f15a0b9b9828cdd7cb489 Mon Sep 17 00:00:00 2001 From: "dveditz%netscape.com" Date: Mon, 24 Apr 2000 13:53:38 +0000 Subject: [PATCH] First cut at chrome install --- xpinstall/public/nsIDOMInstallTriggerGlobal.h | 2 + xpinstall/res/Makefile.in | 9 - xpinstall/res/content/institems.xul | 3 +- xpinstall/res/locale/en-US/MANIFEST | 1 - xpinstall/res/locale/en-US/Makefile.in | 1 - xpinstall/res/locale/en-US/institems.dtd | 3 +- xpinstall/res/locale/en-US/makefile.win | 2 - .../res/locale/en-US/xpinstall.properties | 6 + xpinstall/res/makefile.win | 10 -- xpinstall/src/nsInstall.cpp | 4 +- xpinstall/src/nsInstall.h | 56 +++--- xpinstall/src/nsInstallTrigger.cpp | 52 +++++- xpinstall/src/nsInstallTrigger.h | 7 +- xpinstall/src/nsJSInstall.cpp | 59 ++---- xpinstall/src/nsJSInstallTriggerGlobal.cpp | 89 ++++++++- xpinstall/src/nsSoftwareUpdateRun.cpp | 21 ++- xpinstall/src/nsXPInstallManager.cpp | 170 ++++++++++++------ xpinstall/src/nsXPInstallManager.h | 6 +- 18 files changed, 329 insertions(+), 172 deletions(-) diff --git a/xpinstall/public/nsIDOMInstallTriggerGlobal.h b/xpinstall/public/nsIDOMInstallTriggerGlobal.h index bb130e2a9ca9..7a7e2ab5c55f 100644 --- a/xpinstall/public/nsIDOMInstallTriggerGlobal.h +++ b/xpinstall/public/nsIDOMInstallTriggerGlobal.h @@ -48,6 +48,8 @@ public: NS_IMETHOD Install(nsXPITriggerInfo* aInfo, PRBool* aReturn)=0; + NS_IMETHOD InstallChrome(PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn)=0; + NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRBool* aReturn)=0; NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0; diff --git a/xpinstall/res/Makefile.in b/xpinstall/res/Makefile.in index 66b5862befd5..218e362eb6f2 100644 --- a/xpinstall/res/Makefile.in +++ b/xpinstall/res/Makefile.in @@ -28,14 +28,5 @@ include $(DEPTH)/config/autoconf.mk DIRS = locale content skin -EXPORT_RESOURCE_XPINSTALL = \ - $(srcdir)/progress.xul \ - $(srcdir)/progress.html \ - $(srcdir)/progress.css \ - $(NULL) - include $(topsrcdir)/config/rules.mk -install:: - $(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall - diff --git a/xpinstall/res/content/institems.xul b/xpinstall/res/content/institems.xul index b51fb84a08b9..ce0698806862 100644 --- a/xpinstall/res/content/institems.xul +++ b/xpinstall/res/content/institems.xul @@ -19,6 +19,7 @@ Rights Reserved. Contributor(s): Don Bragg (dbragg@netscape.com) + Dan Veditz --> @@ -30,7 +31,7 @@ Contributor(s): diff --git a/xpinstall/res/locale/en-US/MANIFEST b/xpinstall/res/locale/en-US/MANIFEST index 6f8878988f8b..3187df39d955 100644 --- a/xpinstall/res/locale/en-US/MANIFEST +++ b/xpinstall/res/locale/en-US/MANIFEST @@ -1,4 +1,3 @@ xpinstall.properties -progress.dtd xpistatus.dtd institems.dtd diff --git a/xpinstall/res/locale/en-US/Makefile.in b/xpinstall/res/locale/en-US/Makefile.in index 7f97f81e5183..1ecef1c3279b 100644 --- a/xpinstall/res/locale/en-US/Makefile.in +++ b/xpinstall/res/locale/en-US/Makefile.in @@ -28,7 +28,6 @@ include $(DEPTH)/config/autoconf.mk EXPORT_RESOURCE_XPINSTALL = \ $(srcdir)/xpinstall.properties \ - $(srcdir)/progress.dtd \ $(srcdir)/xpistatus.dtd \ $(srcdir)/institems.dtd \ $(NULL) diff --git a/xpinstall/res/locale/en-US/institems.dtd b/xpinstall/res/locale/en-US/institems.dtd index 3f1c53cf0d8e..4772eb4cc731 100644 --- a/xpinstall/res/locale/en-US/institems.dtd +++ b/xpinstall/res/locale/en-US/institems.dtd @@ -3,6 +3,7 @@ - + + \ No newline at end of file diff --git a/xpinstall/res/locale/en-US/makefile.win b/xpinstall/res/locale/en-US/makefile.win index 4ba37b09b0a2..e57857bd9a35 100644 --- a/xpinstall/res/locale/en-US/makefile.win +++ b/xpinstall/res/locale/en-US/makefile.win @@ -26,14 +26,12 @@ DEPTH=..\..\..\.. include <$(DEPTH)\config\rules.mak> install:: - $(MAKE_INSTALL) progress.dtd $(DIST)\bin\chrome\communicator\locale\xpinstall $(MAKE_INSTALL) xpistatus.dtd $(DIST)\bin\chrome\communicator\locale\xpinstall $(MAKE_INSTALL) xpinstall.properties $(DIST)\bin\chrome\communicator\locale\xpinstall $(MAKE_INSTALL) institems.dtd $(DIST)\bin\chrome\communicator\locale\xpinstall clobber:: - rm -f $(DIST)\bin\chrome\communicator\locale\xpinstall\progress.dtd rm -f $(DIST)\bin\chrome\communicator\locale\xpinstall\xpistatus.dtd rm -f $(DIST)\bin\chrome\communicator\locale\xpinstall\xpinstall.properties rm -f $(DIST)\bin\chrome\communicator\locale\xpinstall\institems.dtd diff --git a/xpinstall/res/locale/en-US/xpinstall.properties b/xpinstall/res/locale/en-US/xpinstall.properties index 81586f2beb3f..49bb912563a4 100644 --- a/xpinstall/res/locale/en-US/xpinstall.properties +++ b/xpinstall/res/locale/en-US/xpinstall.properties @@ -46,6 +46,12 @@ Uninstall=Uninstalling: %s FinishingInstallMsg=Finishing install... please wait. +ApplyNowSkin=Use this theme +ApplyNowLocale=Use this locale + +ConfirmSkin=Install the theme "%1$S" from %2$S? +ConfirmLocale=Install the locale "%1$S" from %2$S? + #-------------------------------------------------------------------- # Miscellaneous diff --git a/xpinstall/res/makefile.win b/xpinstall/res/makefile.win index fcb79c406f1f..55ad3c1398d0 100644 --- a/xpinstall/res/makefile.win +++ b/xpinstall/res/makefile.win @@ -24,13 +24,3 @@ DEPTH=..\.. DIRS = locale content skin include <$(DEPTH)\config\rules.mak> - -install:: $(DLL) - $(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall - $(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall - $(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall - -clobber:: - rm -f $(DIST)\res\xpinstall\progress.xul - rm -f $(DIST)\res\xpinstall\progress.css - rm -f $(DIST)\res\xpinstall\progress.html diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index b351db76c9c5..95440d5a347a 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -87,8 +87,6 @@ static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); -#define XPINSTALL_BUNDLE_URL "chrome://communicator/locale/xpinstall/xpinstall.properties" - // filename length maximums #ifdef XP_MAC #define MAX_NAME_LENGTH 31 @@ -105,7 +103,7 @@ MOZ_DECL_CTOR_COUNTER(nsInstallInfo); nsInstallInfo::nsInstallInfo(nsIFile* aFile, const PRUnichar* aURL, const PRUnichar* aArgs, - long flags, + PRUint32 flags, nsIXPINotifier* aNotifier) : mError(0), mFlags(flags), diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index 19b77d074d62..4a67f6c729a9 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -58,6 +58,8 @@ #include "nsIEnumerator.h" #include "nsIZipReader.h" +#define XPINSTALL_BUNDLE_URL "chrome://communicator/locale/xpinstall/xpinstall.properties" + class nsInstallInfo { public: @@ -65,7 +67,7 @@ class nsInstallInfo nsInstallInfo( nsIFile* aFile, const PRUnichar* aURL, const PRUnichar* aArgs, - long aFlags, + PRUint32 aFlags, nsIXPINotifier* aNotifier); virtual ~nsInstallInfo(); @@ -76,15 +78,15 @@ class nsInstallInfo void GetArguments(nsString& aArgs) { aArgs = mArgs; } - long GetFlags() { return mFlags; } + PRUint32 GetFlags() { return mFlags; } nsIXPINotifier* GetNotifier() { return mNotifier; }; - + private: - + nsresult mError; - long mFlags; + PRUint32 mFlags; nsString mURL; nsString mArgs; @@ -108,8 +110,8 @@ class nsInstall friend class nsWinProfile; public: - - enum + + enum { BAD_PACKAGE_NAME = -200, UNEXPECTED_ERROR = -201, @@ -171,12 +173,12 @@ class nsInstall nsInstall(nsIZipReader * theJARFile); virtual ~nsInstall(); - + PRInt32 SetScriptObject(void* aScriptObject); PRInt32 SaveWinRegPrototype(void* aScriptObject); PRInt32 SaveWinProfilePrototype(void* aScriptObject); - + JSObject* RetrieveWinRegPrototype(void); JSObject* RetrieveWinProfilePrototype(void); @@ -184,17 +186,17 @@ class nsInstall PRInt32 GetRegPackageName(nsString& aRegPackageName); PRInt32 AbortInstall(PRInt32 aErrorNumber); - + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32 aMode, 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, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32 aMode, 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(nsInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn); @@ -202,14 +204,14 @@ class nsInstall 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, 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); @@ -220,7 +222,7 @@ class nsInstall PRInt32 SetPackageFolder(nsInstallFolder& aFolder); PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn); PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn); - + PRInt32 FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn); PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsIFile** aReturn); PRInt32 FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn); @@ -258,9 +260,12 @@ class nsInstall void GetInstallURL(nsString& url); void SetInstallURL(const nsString& url); + PRUint32 GetInstallFlags() { return mInstallFlags; } + void SetInstallFlags(PRUint32 aFlags) { mInstallFlags = aFlags; } + PRBool GetStatusSent() { return mStatusSent; } PRBool InInstallTransaction(void) { return mInstalledFiles != nsnull; } - + PRInt32 Alert(nsString& string); PRInt32 Confirm(nsString& string, PRBool* aReturn); void InternalAbort(PRInt32 errcode); @@ -269,21 +274,22 @@ class nsInstall private: JSObject* mScriptObject; - + JSObject* mWinRegObject; JSObject* mWinProfileObject; nsCOMPtr mJarFileLocation; nsIZipReader* mJarFileData; - + nsString mInstallArguments; nsString mInstallURL; + PRUint32 mInstallFlags; nsInstallFolder* mPackageFolder; PRBool mUserCancelled; PRBool mStatusSent; - + PRBool mUninstallPackage; PRBool mRegisterPackage; PRBool mStartInstallCompleted; @@ -295,21 +301,21 @@ class nsInstall nsVoidArray* mInstalledFiles; //nsCOMPtr mInstalledFiles; nsHashtable* mPatchList; - + nsIXPINotifier *mNotifier; nsCOMPtr mStringBundle; PRInt32 mLastError; - + void ParseFlags(int flags); PRInt32 SanityCheck(void); void GetTime(nsString &aString); - + PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName ); PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName ); - + void CurrentUserNode(nsString& userRegNode); PRBool BadRegName(const nsString& regName); @@ -319,7 +325,7 @@ class nsInstall PRInt32 ScheduleForInstall(nsInstallObject* ob); - static void DeleteVector(nsVoidArray* vector); + static void DeleteVector(nsVoidArray* vector); }; nsresult MakeUnique(nsILocalFile* file); diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 878e24e1071e..5b1b0d10bb6d 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -51,11 +51,10 @@ static NS_DEFINE_IID(kIInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID); - nsInstallTrigger::nsInstallTrigger() { mScriptObject = nsnull; - NS_INIT_REFCNT(); + NS_INIT_ISUPPORTS(); } nsInstallTrigger::~nsInstallTrigger() @@ -165,12 +164,12 @@ nsInstallTrigger::UpdateEnabled(PRBool* aReturn) NS_IMETHODIMP nsInstallTrigger::Install(nsXPITriggerInfo* aTrigger, PRBool* aReturn) { - nsresult rv; + NS_ASSERTION(aReturn, "Invalid pointer arg"); *aReturn = PR_FALSE; PRBool enabled; - UpdateEnabled(&enabled); - if (!enabled) + nsresult rv = UpdateEnabled(&enabled); + if (NS_FAILED(rv) || !enabled) { delete aTrigger; return NS_OK; @@ -180,7 +179,7 @@ nsInstallTrigger::Install(nsXPITriggerInfo* aTrigger, PRBool* aReturn) if (mgr) { // The Install manager will delete itself when done - rv = mgr->InitManager( aTrigger ); + rv = mgr->InitManager( aTrigger, 0 ); if (NS_SUCCEEDED(rv)) *aReturn = PR_TRUE; } @@ -195,6 +194,45 @@ nsInstallTrigger::Install(nsXPITriggerInfo* aTrigger, PRBool* aReturn) } +NS_IMETHODIMP +nsInstallTrigger::InstallChrome(PRUint32 aType, nsXPITriggerItem *aItem, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + NS_ENSURE_ARG_POINTER(aItem); + *aReturn = PR_FALSE; + + + // make sure we're allowing installs + PRBool enabled; + nsresult rv = UpdateEnabled(&enabled); + if (NS_FAILED(rv) || !enabled) + return NS_OK; + + + // The Install manager will delete itself when done, once we've called + // InitManager. Before then **WE** must delete it + nsXPInstallManager *mgr = new nsXPInstallManager(); + if (mgr) + { + nsXPITriggerInfo* trigger = new nsXPITriggerInfo(); + if ( trigger ) + { + trigger->Add( aItem ); + + // The Install manager will delete itself when done + rv = mgr->InitManager( trigger, aType ); + *aReturn = PR_TRUE; + } + else + { + rv = NS_ERROR_OUT_OF_MEMORY; + delete mgr; + } + } + + return NS_OK; +} + NS_IMETHODIMP nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRBool* aReturn) { @@ -219,7 +257,7 @@ nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRBo { trigger->Add( item ); // The Install manager will delete itself when done - rv = mgr->InitManager( trigger ); + rv = mgr->InitManager( trigger, 0 ); *aReturn = PR_TRUE; } else diff --git a/xpinstall/src/nsInstallTrigger.h b/xpinstall/src/nsInstallTrigger.h index 745c1ecd2bf4..6905dc4ea408 100644 --- a/xpinstall/src/nsInstallTrigger.h +++ b/xpinstall/src/nsInstallTrigger.h @@ -14,7 +14,11 @@ #include "nsSoftwareUpdate.h" #include "nsXPITriggerInfo.h" - +#define CHROMETYPE_SAFESKIN 1 +#define CHROMETYPE_LOCALE 2 +#define CHROMETYPE_SAFEMAX CHROMETYPE_LOCALE +#define CHROMETYPE_SCRIPTSKIN 3 +#define CHROMETYPE_PACKAGE 4 class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTriggerGlobal @@ -32,6 +36,7 @@ class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTrigger NS_IMETHOD UpdateEnabled(PRBool* aReturn); NS_IMETHOD Install(nsXPITriggerInfo *aInfo, PRBool* aReturn); + NS_IMETHOD InstallChrome(PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn); NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index 3a5b54cd5258..c35e23ce532c 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -57,10 +57,11 @@ enum Install_slots INSTALL_JARFILE = -3, INSTALL_ARGUMENTS = -4, INSTALL_URL = -5, - INSTALL_STATUSSENT = -6, - INSTALL_INSTALL = -7, - INSTALL_FILEOP = -8, - INSTALL_INSTALLED_FILES = -9 + INSTALL_FLAGS = -6, + INSTALL_STATUSSENT = -7, + INSTALL_INSTALL = -8, + INSTALL_FILEOP = -9, + INSTALL_INSTALLED_FILES = -10 }; // prototype for fileOp object @@ -146,6 +147,10 @@ GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) break; } + case INSTALL_FLAGS: + *vp = INT_TO_JSVAL( a->GetInstallFlags() ); + break; + case INSTALL_STATUSSENT: *vp = BOOLEAN_TO_JSVAL( a->GetStatusSent() ); break; @@ -1766,6 +1771,7 @@ static JSPropertySpec InstallProperties[] = {"jarfile", INSTALL_JARFILE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"arguments", INSTALL_ARGUMENTS, JSPROP_ENUMERATE | JSPROP_READONLY}, {"url", INSTALL_URL, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"flags", INSTALL_FLAGS, JSPROP_ENUMERATE | JSPROP_READONLY}, {"_statusSent", INSTALL_STATUSSENT, JSPROP_READONLY}, {"Install", INSTALL_INSTALL, JSPROP_READONLY}, {"File", INSTALL_FILEOP, JSPROP_READONLY}, @@ -1885,49 +1891,6 @@ static JSFunctionSpec InstallMethods[] = {"abortInstall", InstallAbortInstall, 1}, {"finalizeInstall", InstallFinalizeInstall, 0}, {"startInstall", InstallStartInstall, 4}, - {"AbortInstall", InstallAbortInstall, 1}, - {"AddDirectory", InstallAddDirectory, 6}, - {"AddSubcomponent", InstallAddSubcomponent, 6}, - {"DeleteComponent", InstallDeleteComponent, 1}, - {"DeleteFile", InstallDeleteFile, 2}, - {"DiskSpaceAvailable", InstallDiskSpaceAvailable, 1}, - {"Execute", InstallExecute, 2}, - {"FinalizeInstall", InstallFinalizeInstall, 0}, - {"Gestalt", InstallGestalt, 1}, - {"GetComponentFolder", InstallGetComponentFolder, 2}, - {"GetFolder", InstallGetFolder, 2}, - {"GetLastError", InstallGetLastError, 0}, - {"GetWinProfile", InstallGetWinProfile, 2}, - {"GetWinRegistry", InstallGetWinRegistry, 0}, - {"LoadResources", InstallLoadResources, 1}, - {"Patch", InstallPatch, 5}, - {"ResetError", InstallResetError, 0}, - {"SetPackageFolder", InstallSetPackageFolder, 1}, - {"StartInstall", InstallStartInstall, 4}, - {"Uninstall", InstallUninstall, 1}, - {"DirCreate", InstallFileOpDirCreate, 1}, - {"DirGetParent", InstallFileOpDirGetParent, 1}, - {"DirRemove", InstallFileOpDirRemove, 2}, - {"DirRename", InstallFileOpDirRename, 2}, - {"FileCopy", InstallFileOpFileCopy, 2}, - {"FileDelete", InstallFileOpFileRemove, 1}, - {"FileExists", InstallFileOpFileExists, 1}, - {"FileExecute", InstallFileOpFileExecute, 2}, - {"FileGetNativeVersion", InstallFileOpFileGetNativeVersion, 1}, - {"FileGetDiskSpaceAvailable", InstallFileOpFileGetDiskSpaceAvailable,1}, - {"FileGetModDate", InstallFileOpFileGetModDate, 1}, - {"FileGetSize", InstallFileOpFileGetSize, 1}, - {"FileIsDirectory", InstallFileOpFileIsDirectory, 1}, - {"FileIsFile", InstallFileOpFileIsFile, 1}, - {"FileModDateChanged", InstallFileOpFileModDateChanged, 2}, - {"FileMove", InstallFileOpFileMove, 2}, - {"FileRename", InstallFileOpFileRename, 2}, - {"FileWindowsShortcut", InstallFileOpFileWindowsShortcut, 7}, - {"FileMacAlias", InstallFileOpFileMacAlias, 2}, - {"FileUnixLink", InstallFileOpFileUnixLink, 2}, - {"LogComment", InstallLogComment, 1}, - {"Alert", InstallAlert, 1}, - {"Confirm", InstallConfirm, 2}, {0} }; @@ -1940,6 +1903,7 @@ JSObject * InitXPInstallObjects(JSContext *jscontext, nsIFile* jarfile, const PRUnichar* url, const PRUnichar* args, + PRUint32 flags, nsIZipReader * theJARFile) { JSObject *installObject = nsnull; @@ -1976,6 +1940,7 @@ JSObject * InitXPInstallObjects(JSContext *jscontext, nativeInstallObject->SetJarFileLocation(jarfile); nativeInstallObject->SetInstallArguments(args); nativeInstallObject->SetInstallURL(url); + nativeInstallObject->SetInstallFlags(flags); JS_SetPrivate(jscontext, installObject, nativeInstallObject); nativeInstallObject->SetScriptObject(installObject); diff --git a/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/xpinstall/src/nsJSInstallTriggerGlobal.cpp index 81348a98ab08..7994c0c03b8b 100644 --- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -31,6 +31,7 @@ #include "nsString.h" #include "nsIDOMInstallVersion.h" #include "nsIDOMInstallTriggerGlobal.h" +#include "nsInstallTrigger.h" #include "nsXPITriggerInfo.h" #include "nsRepository.h" @@ -236,6 +237,80 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg return JS_FALSE; } + +// +// Native method InstallChrome +// +PR_STATIC_CALLBACK(JSBool) +InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj); + PRBool nativeRet; + PRUint32 chromeType; + nsAutoString baseURL; + nsAutoString sourceURL; + nsAutoString name; + + *rval = JSVAL_FALSE; + + if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) ) { + return JS_FALSE; + } + + + // make sure XPInstall is enabled, return if not + PRBool enabled = PR_FALSE; + nativeThis->UpdateEnabled(&enabled); + if (!enabled) + return JS_TRUE; + + + // get window.location to construct relative URLs + JSObject* global = JS_GetGlobalObject(cx); + if (global) + { + jsval v; + if (JS_GetProperty(cx,global,"location",&v)) + { + ConvertJSValToStr( baseURL, cx, v ); + PRInt32 lastslash = baseURL.RFindChar('/'); + if (lastslash != kNotFound) + { + baseURL.Truncate(lastslash+1); + } + } + } + + + + if ( argc >= 3 ) + { + chromeType = JSVAL_TO_INT(argv[0]); + ConvertJSValToStr(sourceURL, cx, argv[1]); + ConvertJSValToStr(name, cx, argv[2]); + + if ( chromeType == CHROMETYPE_SAFESKIN || chromeType == CHROMETYPE_LOCALE ) + { + nsresult rv; + + nsXPITriggerItem* item = new nsXPITriggerItem(name.GetUnicode(), + sourceURL.GetUnicode()); + + if (item && item->IsRelativeURL()) + item->mURL.Insert( baseURL, 0 ); + + rv = nativeThis->InstallChrome(chromeType, item, &nativeRet); + + if (NS_FAILED(rv)) + return JS_FALSE; + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + } + return JS_TRUE; +} + + // // Native method StartSoftwareUpdate // @@ -571,17 +646,19 @@ JSClass InstallTriggerGlobalClass = { // static JSFunctionSpec InstallTriggerGlobalMethods[] = { + // -- obsolete forms, do not document. Kept for 4.x compatibility {"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0}, - {"Install", InstallTriggerGlobalInstall, 2}, {"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2}, {"ConditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5}, {"CompareVersion", InstallTriggerGlobalCompareVersion, 5}, {"GetVersion", InstallTriggerGlobalGetVersion, 2}, - // -- new forms to match JS style -- {"updateEnabled", InstallTriggerGlobalUpdateEnabled, 0}, - {"install", InstallTriggerGlobalInstall, 2}, - {"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2}, {"conditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5}, + // -- new forms to match JS style -- + {"enabled", InstallTriggerGlobalUpdateEnabled, 0}, + {"install", InstallTriggerGlobalInstall, 2}, + {"installChrome", InstallTriggerGlobalInstallChrome, 2}, + {"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2}, {"compareVersion", InstallTriggerGlobalCompareVersion, 5}, {"getVersion", InstallTriggerGlobalGetVersion, 2}, {0} @@ -595,6 +672,10 @@ static JSConstDoubleSpec diff_constants[] = { nsIDOMInstallTriggerGlobal::REL_DIFF, "REL_DIFF" }, { nsIDOMInstallTriggerGlobal::BLD_DIFF, "BLD_DIFF" }, { nsIDOMInstallTriggerGlobal::EQUAL, "EQUAL" }, + { CHROMETYPE_SAFESKIN, "THEME" }, + { CHROMETYPE_LOCALE, "LOCALE" }, + { CHROMETYPE_SCRIPTSKIN, "SUPERSKIN" }, + { CHROMETYPE_PACKAGE, "PACKAGE" }, {0} }; diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index 8b78a36afae7..62c006295156 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -53,14 +53,14 @@ static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, nsIFile* jarfile, const PRUnichar* url, const PRUnichar* args, nsIZipReader* hZip); +extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, nsIFile* jarfile, const PRUnichar* url, const PRUnichar* args, PRUint32 flags, nsIZipReader* hZip); extern nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype); extern nsresult InitInstallTriggerGlobalClass(JSContext *jscontext, JSObject *global, void** prototype); // Defined in this file: static void XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); static PRInt32 GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptBuffer, PRUint32 *scriptLength); -static nsresult SetupInstallContext(nsIZipReader* hZip, nsIFile* jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); +static nsresult SetupInstallContext(nsIZipReader* hZip, nsIFile* jarFile, const PRUnichar* url, const PRUnichar* args, PRUint32 flags, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); extern "C" void RunInstallOnThread(void *data); @@ -246,6 +246,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB // Argument : const char* jarFile - native filepath to where jar exists on disk // Argument : const PRUnichar* url - URL of where this package came from // Argument : const PRUnichar* args - any arguments passed into the javascript context +// Argument : PRUint32 flags - bitmask of flags passed in // Argument : JSRuntime *jsRT - A valid JS Runtime // Argument : JSContext **jsCX - Created context, destroy via JS_DestroyContext // Argument : JSObject **jsGlob - created global object @@ -253,7 +254,8 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB static nsresult SetupInstallContext(nsIZipReader* hZip, nsIFile* jarFile, const PRUnichar* url, - const PRUnichar* args, + const PRUnichar* args, + PRUint32 flags, JSRuntime *rt, JSContext **jsCX, JSObject **jsGlob) @@ -276,7 +278,7 @@ static nsresult SetupInstallContext(nsIZipReader* hZip, JS_SetErrorReporter(cx, XPInstallErrorReporter); - glob = InitXPInstallObjects(cx, nsnull, jarFile, url, args, hZip); + glob = InitXPInstallObjects(cx, nsnull, jarFile, url, args, flags, hZip); // Init standard classes JS_InitStandardClasses(cx, glob); @@ -403,12 +405,13 @@ extern "C" void RunInstallOnThread(void *data) // service not available (wizard context?) // create our own runtime ownRuntime = PR_TRUE; - rt = JS_Init(4L * 1024L * 1024L); + rt = JS_Init(4L * 1024L * 1024L); } - rv = SetupInstallContext( hZip, jarpath, + rv = SetupInstallContext( hZip, jarpath, url.GetUnicode(), - args.GetUnicode(), + args.GetUnicode(), + installInfo->GetFlags(), rt, &cx, &glob); if (NS_SUCCEEDED(rv)) @@ -417,9 +420,9 @@ extern "C" void RunInstallOnThread(void *data) jsval rval; jsval installedFiles; - PRBool ok = JS_EvaluateScript( cx, + PRBool ok = JS_EvaluateScript( cx, glob, - scriptBuffer, + scriptBuffer, scriptLength, nsnull, 0, diff --git a/xpinstall/src/nsXPInstallManager.cpp b/xpinstall/src/nsXPInstallManager.cpp index d94dfcd865fc..347903e829c3 100644 --- a/xpinstall/src/nsXPInstallManager.cpp +++ b/xpinstall/src/nsXPInstallManager.cpp @@ -42,9 +42,11 @@ #include "nsISoftwareUpdate.h" #include "nsSoftwareUpdateIIDs.h" +#include "nsTextFormatter.h" #include "nsXPITriggerInfo.h" #include "nsXPInstallManager.h" +#include "nsInstallTrigger.h" #include "nsInstallProgressDialog.h" #include "nsInstallResources.h" #include "nsSpecialSystemDirectory.h" @@ -54,6 +56,7 @@ #include "nsDirectoryService.h" #include "nsIAppShellComponentImpl.h" +#include "nsINetSupportDialogService.h" #include "nsIPrompt.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -62,16 +65,16 @@ static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kDialogParamBlockCID, NS_DialogParamBlock_CID); +static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); #include "nsIEventQueueService.h" static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -#define XPINSTALL_BUNDLE_URL "chrome://communicator/locale/xpinstall/xpinstall.properties" - nsXPInstallManager::nsXPInstallManager() : mTriggers(0), mItem(0), mNextItem(0), mNumJars(0), - mFinalizing(PR_FALSE), mCancelled(PR_FALSE), mContentLength(0) + mFinalizing(PR_FALSE), mCancelled(PR_FALSE), mChromeType(0), + mSelectChrome(PR_TRUE), mContentLength(0) { NS_INIT_ISUPPORTS(); @@ -142,13 +145,14 @@ nsXPInstallManager::QueryInterface(REFNSIID aIID,void** aInstancePtr) NS_IMETHODIMP -nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers) +nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers, PRUint32 aChromeType) { nsresult rv = NS_OK; nsCOMPtr ioParamBlock; PRBool OKtoInstall = PR_FALSE; mTriggers = aTriggers; + mChromeType = aChromeType; if ( !mTriggers || mTriggers->Size() == 0 ) { @@ -172,48 +176,10 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers) LoadDialogWithNames(ioParamBlock); - // Now do the stuff to create a window and pass the JS args to it. - NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv ); - if ( NS_SUCCEEDED( rv ) ) - { - nsCOMPtr hiddenWindow; - JSContext* jsContext; - rv = appShell->GetHiddenWindowAndJSContext( getter_AddRefs(hiddenWindow), &jsContext); - if (NS_SUCCEEDED(rv)) - { - void* stackPtr; - jsval *argv = JS_PushArguments( jsContext, - &stackPtr, - "sss%ip", - "chrome://communicator/content/xpinstall/institems.xul", - "_blank", - "chrome,modal", - (const nsIID*)(&NS_GET_IID(nsIDialogParamBlock)), - (nsISupports*)ioParamBlock); - - if (argv) - { - nsCOMPtr newWindow; - rv = hiddenWindow->OpenDialog( jsContext, - argv, - 4, - getter_AddRefs( newWindow)); - if (NS_SUCCEEDED(rv)) - { - JS_PopArguments( jsContext, stackPtr); - - //Now get which button was pressed from the ParamBlock - PRInt32 buttonPressed = 0; - ioParamBlock->GetInt( 0, &buttonPressed ); - OKtoInstall = buttonPressed ? PR_FALSE : PR_TRUE; - } - } - else - { - rv = NS_ERROR_FAILURE; // fix, better error code?? - } - } - } + if (mChromeType == 0 || mChromeType > CHROMETYPE_SAFEMAX ) + OKtoInstall = ConfirmInstall(ioParamBlock); + else + OKtoInstall = ConfirmChromeInstall(); } // --- create and open the progress dialog @@ -270,6 +236,114 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers) return rv; } +PRBool nsXPInstallManager::ConfirmInstall(nsIDialogParamBlock* ioParamBlock) +{ + nsresult rv = NS_OK; + PRBool result = PR_FALSE; + + // create a window and pass the JS args to it. + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv ); + if ( NS_SUCCEEDED( rv ) ) + { + nsCOMPtr hiddenWindow; + JSContext* jsContext; + rv = appShell->GetHiddenWindowAndJSContext( getter_AddRefs(hiddenWindow), &jsContext); + if (NS_SUCCEEDED(rv)) + { + void* stackPtr; + jsval *argv = JS_PushArguments( jsContext, + &stackPtr, + "sss%ip", + "chrome://communicator/content/xpinstall/institems.xul", + "_blank", + "chrome,modal", + (const nsIID*)(&NS_GET_IID(nsIDialogParamBlock)), + (nsISupports*)ioParamBlock); + + if (argv) + { + nsCOMPtr newWindow; + rv = hiddenWindow->OpenDialog( jsContext, + argv, + 4, + getter_AddRefs( newWindow)); + if (NS_SUCCEEDED(rv)) + { + JS_PopArguments( jsContext, stackPtr); + + //Now get which button was pressed from the ParamBlock + PRInt32 buttonPressed = 0; + ioParamBlock->GetInt( 0, &buttonPressed ); + result = buttonPressed ? PR_FALSE : PR_TRUE; + } + } + } + } + + return result; +} + +PRBool nsXPInstallManager::ConfirmChromeInstall() +{ + nsXPITriggerItem* item = (nsXPITriggerItem*)mTriggers->Get(0); + + // get the dialog strings + nsresult rv; + nsXPIDLString applyNowText; + nsXPIDLString confirmFormat; + PRUnichar* confirmText = nsnull; + nsCOMPtr xpiBundle; + NS_WITH_SERVICE( nsIStringBundleService, bundleSvc, + kStringBundleServiceCID, &rv ); + if (NS_SUCCEEDED(rv) && bundleSvc) + { + rv = bundleSvc->CreateBundle( XPINSTALL_BUNDLE_URL, nsnull, + getter_AddRefs(xpiBundle) ); + if (NS_SUCCEEDED(rv) && xpiBundle) + { + if ( mChromeType == CHROMETYPE_LOCALE ) + { + xpiBundle->GetStringFromName( + NS_ConvertASCIItoUCS2("ApplyNowLocale").GetUnicode(), + getter_Copies(applyNowText)); + xpiBundle->GetStringFromName( + NS_ConvertASCIItoUCS2("ConfirmLocale").GetUnicode(), + getter_Copies(confirmFormat)); + } + else + { + xpiBundle->GetStringFromName( + NS_ConvertASCIItoUCS2("ApplyNowSkin").GetUnicode(), + getter_Copies(applyNowText)); + xpiBundle->GetStringFromName( + NS_ConvertASCIItoUCS2("ConfirmSkin").GetUnicode(), + getter_Copies(confirmFormat)); + } + + confirmText = nsTextFormatter::smprintf(confirmFormat, + item->mName.GetUnicode(), + item->mURL.GetUnicode()); + } + } + + + // confirmation dialog + PRBool bInstall = PR_FALSE; + if (confirmText) + { + NS_WITH_SERVICE(nsIPrompt, dlgService, kNetSupportDialogCID, &rv); + if (NS_SUCCEEDED(rv)) + { + rv = dlgService->ConfirmCheck( confirmText, + applyNowText, + &mSelectChrome, + &bInstall ); + } + } + + return bInstall; +} + NS_IMETHODIMP nsXPInstallManager::DialogOpened(nsISupports* aWindow) { @@ -430,10 +504,6 @@ void nsXPInstallManager::Shutdown() // proxy exists: we're being called from script thread mProxy->Close(); } -// else if (mDlg) -// mDlg->Close(); - -// mDlg = 0; // Clean up downloaded files nsXPITriggerItem* item; diff --git a/xpinstall/src/nsXPInstallManager.h b/xpinstall/src/nsXPInstallManager.h index 7ab80789fd45..046172e6b057 100644 --- a/xpinstall/src/nsXPInstallManager.h +++ b/xpinstall/src/nsXPInstallManager.h @@ -63,7 +63,7 @@ class nsXPInstallManager : public nsIXPINotifier, NS_DECL_ISUPPORTS - NS_IMETHOD InitManager( nsXPITriggerInfo* aTrigger ); + NS_IMETHOD InitManager( nsXPITriggerInfo* aTrigger, PRUint32 chromeType ); // nsIStreamObserver NS_DECL_NSISTREAMOBSERVER @@ -88,6 +88,8 @@ class nsXPInstallManager : public nsIXPINotifier, NS_IMETHOD DownloadNext(); void Shutdown(); void LoadDialogWithNames(nsIDialogParamBlock* ioParamBlock); + PRBool ConfirmInstall(nsIDialogParamBlock* ioParamBlock); + PRBool ConfirmChromeInstall(); nsXPITriggerInfo* mTriggers; nsXPITriggerItem* mItem; @@ -95,6 +97,8 @@ class nsXPInstallManager : public nsIXPINotifier, PRInt32 mNumJars; PRBool mFinalizing; PRBool mCancelled; + PRUint32 mChromeType; + PRBool mSelectChrome; PRInt32 mContentLength; nsCOMPtr mProxy;