From c6d2b1732d84e730ba83c35910233380f7b61204 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Sun, 16 May 1999 19:11:25 +0000 Subject: [PATCH] Adding appshellcomponent interface and init code. --- xpinstall/public/nsISoftwareUpdate.h | 8 +- xpinstall/public/nsSoftwareUpdateIIDs.h | 48 -------- xpinstall/src/makefile.win | 1 + xpinstall/src/nsInstall.cpp | 7 +- xpinstall/src/nsSoftwareUpdate.cpp | 149 +++++++++++++++++------ xpinstall/src/nsSoftwareUpdate.h | 38 +++--- xpinstall/src/nsSoftwareUpdateRun.cpp | 7 +- xpinstall/src/nsSoftwareUpdateStream.cpp | 9 +- 8 files changed, 145 insertions(+), 122 deletions(-) diff --git a/xpinstall/public/nsISoftwareUpdate.h b/xpinstall/public/nsISoftwareUpdate.h index 7ad7d1ad75f0..5bd26e43ea19 100644 --- a/xpinstall/public/nsISoftwareUpdate.h +++ b/xpinstall/public/nsISoftwareUpdate.h @@ -32,6 +32,10 @@ #include "nsIXPInstallProgressNotifier.h" +#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall" +#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component" + + #define NS_ISOFTWAREUPDATE_IID \ { 0x18c2f992, \ 0xb09f, \ @@ -40,11 +44,11 @@ } -class nsISoftwareUpdate : public nsISupports +class nsISoftwareUpdate : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID) - + NS_IMETHOD InstallJar(const nsString& fromURL, const nsString& localFile, long flags) = 0; diff --git a/xpinstall/public/nsSoftwareUpdateIIDs.h b/xpinstall/public/nsSoftwareUpdateIIDs.h index b372c0cd87bf..7656cb666e63 100644 --- a/xpinstall/public/nsSoftwareUpdateIIDs.h +++ b/xpinstall/public/nsSoftwareUpdateIIDs.h @@ -34,14 +34,6 @@ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } -#define NS_SoftwareUpdateFactory_CID \ -{ /* 18c2f98a-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f98a, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} - #define NS_SoftwareUpdateInstall_CID \ { /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \ 0x18c2f98b, \ @@ -50,14 +42,6 @@ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } -#define NS_SoftwareUpdateInstallFactory_CID \ -{ /* 18c2f98c-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f98c, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} - #define NS_SoftwareUpdateInstallTrigger_CID \ { /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \ 0x18c2f98d, \ @@ -66,14 +50,6 @@ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } -#define NS_SoftwareUpdateInstallTriggerFactory_CID \ -{ /* 18c2f98e-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f98e, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} - #define NS_SoftwareUpdateInstallVersion_CID \ { /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \ 0x18c2f98f, \ @@ -82,31 +58,7 @@ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } -#define NS_SoftwareUpdateInstallVersionFactory_CID \ -{ /* 18c2f990-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f990, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} -#if 0 -#define NS_SoftwareUpdateInstallFolder_CID \ -{ /* 18c2f991-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f991, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} - -#define NS_SoftwareUpdateInstallFolderFactory_CID \ -{ /* 18c2f992-b09f-11d2-bcde-00805f0e1353 */ \ - 0x18c2f992, \ - 0xb09f, \ - 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ -} -#endif #endif /* nsSoftwareUpdateIIDs_h___ */ diff --git a/xpinstall/src/makefile.win b/xpinstall/src/makefile.win index df4a33a646f0..472fccd40882 100644 --- a/xpinstall/src/makefile.win +++ b/xpinstall/src/makefile.win @@ -53,6 +53,7 @@ LINCS= \ -I$(PUBLIC)\raptor \ -I$(PUBLIC)\nspr2 \ -I$(PUBLIC)\zlib \ + -I$(PUBLIC)\xpfe\components \ $(NULL) LLIBS = \ diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 2bad56a95563..83104842d304 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -192,10 +192,9 @@ nsInstall::nsInstall() mInstallArguments = ""; nsISoftwareUpdate *su; - nsresult rv = nsComponentManager::CreateInstance( kSoftwareUpdateCID, - nsnull, - kISoftwareUpdateIID, - (void**) &su); + nsresult rv = nsServiceManager::GetService(kSoftwareUpdateCID, + kISoftwareUpdateIID, + (nsISupports**) &su); if (NS_SUCCEEDED(rv)) { diff --git a/xpinstall/src/nsSoftwareUpdate.cpp b/xpinstall/src/nsSoftwareUpdate.cpp index c7c852bde896..e330b43ba601 100644 --- a/xpinstall/src/nsSoftwareUpdate.cpp +++ b/xpinstall/src/nsSoftwareUpdate.cpp @@ -41,6 +41,9 @@ #include "nsTopProgressNotifier.h" #include "nsLoggingProgressNotifier.h" +#include "nsIAppShellComponent.h" +#include "nsIRegistry.h" + /* For Javascript Namespace Access */ #include "nsDOMCID.h" #include "nsIServiceManager.h" @@ -76,36 +79,16 @@ static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID); -nsSoftwareUpdate* nsSoftwareUpdate::mInstance = NULL; nsSoftwareUpdate::nsSoftwareUpdate() { +#ifdef NS_DEBUG + printf("XPInstall Component created\n"); +#endif + NS_INIT_ISUPPORTS(); - Startup(); -} -nsSoftwareUpdate::~nsSoftwareUpdate() -{ - Shutdown(); -} - -nsSoftwareUpdate *nsSoftwareUpdate::GetInstance() -{ - if (mInstance == NULL) - { - mInstance = new nsSoftwareUpdate(); - } - return mInstance; -} - - -NS_IMPL_ISUPPORTS(nsSoftwareUpdate,nsISoftwareUpdate::GetIID()); - - -nsresult -nsSoftwareUpdate::Startup() -{ - /***************************************/ + /***************************************/ /* Create us a queue */ /***************************************/ mInstalling = nsnull; @@ -165,15 +148,13 @@ nsSoftwareUpdate::Startup() nsLoggingProgressNotifier *logger = new nsLoggingProgressNotifier(); RegisterNotifier(logger); - - - return NS_OK; } - - -nsresult -nsSoftwareUpdate::Shutdown() +nsSoftwareUpdate::~nsSoftwareUpdate() { +#ifdef NS_DEBUG + printf("*** XPInstall Component destroyed\n"); +#endif + if (mJarInstallQueue != nsnull) { PRUint32 i=0; @@ -190,9 +171,72 @@ nsSoftwareUpdate::Shutdown() } NR_ShutdownRegistry(); - return NS_OK; } +NS_IMPL_ADDREF( nsSoftwareUpdate ); +NS_IMPL_RELEASE( nsSoftwareUpdate ); + +NS_IMETHODIMP +nsSoftwareUpdate::QueryInterface( REFNSIID anIID, void **anInstancePtr ) +{ + nsresult rv = NS_OK; + /* Check for place to return result. */ + + if ( !anInstancePtr ) + { + rv = NS_ERROR_NULL_POINTER; + } + else + { + /* Initialize result. */ + *anInstancePtr = 0; + /* Check for IIDs we support and cast this appropriately. */ + if ( anIID.Equals( nsISoftwareUpdate::GetIID() ) ) + { + *anInstancePtr = (void*) ( (nsISoftwareUpdate*)this ); + NS_ADDREF_THIS(); + } + else if ( anIID.Equals( nsIAppShellComponent::GetIID() ) ) + { + *anInstancePtr = (void*) ( (nsIAppShellComponent*)this ); + NS_ADDREF_THIS(); + } + else if ( anIID.Equals( kISupportsIID ) ) + { + *anInstancePtr = (void*) ( (nsISupports*) (nsISoftwareUpdate*) this ); + NS_ADDREF_THIS(); + } + else + { + /* Not an interface we support. */\ + rv = NS_NOINTERFACE; + } + } + return rv; +} + + +NS_IMETHODIMP +nsSoftwareUpdate::Initialize( nsIAppShellService *anAppShell, nsICmdLineService *aCmdLineService ) +{ + nsresult rv; + + rv = nsServiceManager::RegisterService( NS_IXPINSTALLCOMPONENT_PROGID, ( (nsISupports*) (nsISoftwareUpdate*) this ) ); + + return rv; +} + +NS_IMETHODIMP +nsSoftwareUpdate::Shutdown() +{ + nsresult rv; + + rv = nsServiceManager::ReleaseService( NS_IXPINSTALLCOMPONENT_PROGID, ( (nsISupports*) (nsISoftwareUpdate*) this ) ); + + return rv; +} + + NS_IMETHODIMP nsSoftwareUpdate::RegisterNotifier(nsIXPInstallProgressNotifier *notifier) { @@ -313,7 +357,7 @@ nsSoftwareUpdateFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void *aResult = NULL; - nsSoftwareUpdate *inst = nsSoftwareUpdate::GetInstance(); + nsSoftwareUpdate *inst = new nsSoftwareUpdate(); if (inst == NULL) return NS_ERROR_OUT_OF_MEMORY; @@ -438,12 +482,45 @@ NSRegisterSelf(nsISupports* aServMgr, const char *path) printf("*** XPInstall is being registered\n"); #endif - rv = compMgr->RegisterComponent(kSoftwareUpdate_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + rv = compMgr->RegisterComponent( kSoftwareUpdate_CID, + NS_IXPINSTALLCOMPONENT_CLASSNAME, + NS_IXPINSTALLCOMPONENT_PROGID, + path, + PR_TRUE, + PR_TRUE ); + if (NS_FAILED(rv)) goto done; + + nsIRegistry *registry; + rv = servMgr->GetService( NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), + (nsISupports**)®istry ); + + if ( NS_SUCCEEDED( rv ) ) + { + registry->Open(); + char buffer[256]; + char *cid = nsSoftwareUpdate::GetCID().ToString(); + PR_snprintf( buffer, + sizeof buffer, + "%s/%s", + NS_IAPPSHELLCOMPONENT_KEY, + cid ? cid : "unknown" ); + delete [] cid; + + nsIRegistry::Key key; + rv = registry->AddSubtree( nsIRegistry::Common, + buffer, + &key ); + servMgr->ReleaseService( NS_REGISTRY_PROGID, registry ); + } + rv = compMgr->RegisterComponent(kInstallTrigger_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; + rv = compMgr->RegisterComponent(kInstallVersion_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); - done: + +done: (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); return rv; } diff --git a/xpinstall/src/nsSoftwareUpdate.h b/xpinstall/src/nsSoftwareUpdate.h index bc5cf8895da0..76c6626659c4 100644 --- a/xpinstall/src/nsSoftwareUpdate.h +++ b/xpinstall/src/nsSoftwareUpdate.h @@ -14,38 +14,35 @@ class nsInstallInfo; #include "nsIScriptExternalNameSet.h" - +#include "nsIAppShellComponent.h" #include "nsIXPInstallProgressNotifier.h" #include "nsTopProgressNotifier.h" -class nsSoftwareUpdate: public nsISoftwareUpdate +class nsSoftwareUpdate: public nsIAppShellComponent, public nsISoftwareUpdate { public: - static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstall_CID; return iid; } + + NS_DEFINE_STATIC_CID_ACCESSOR( NS_SoftwareUpdate_CID ); nsSoftwareUpdate(); virtual ~nsSoftwareUpdate(); - - static nsSoftwareUpdate *GetInstance(); - + NS_DECL_ISUPPORTS + NS_DECL_IAPPSHELLCOMPONENT + + NS_IMETHOD InstallJar(const nsString& fromURL, + const nsString& localFile, + long flags); - - NS_IMETHOD InstallJar(const nsString& fromURL, - const nsString& localFile, - long flags); + NS_IMETHOD RegisterNotifier(nsIXPInstallProgressNotifier *notifier); + + NS_IMETHOD InstallPending(void); - NS_IMETHOD RegisterNotifier(nsIXPInstallProgressNotifier *notifier); - - NS_IMETHOD InstallPending(void); - - NS_IMETHOD InstallJarCallBack(); - NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgressNotifier **notifier); + NS_IMETHOD InstallJarCallBack(); + NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgressNotifier **notifier); private: - nsresult Startup(); - nsresult Shutdown(); nsresult RunNextInstall(); nsresult DeleteScheduledNodes(); @@ -53,11 +50,6 @@ class nsSoftwareUpdate: public nsISoftwareUpdate PRBool mInstalling; nsVector* mJarInstallQueue; nsTopProgressNotifier *mTopLevelObserver; - - static nsSoftwareUpdate* mInstance; - - - }; diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index a4804461d0c0..135b1f3ac69d 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -291,10 +291,9 @@ extern "C" void RunInstallOnThread(void *data) nsISoftwareUpdate *softwareUpdate; - nsresult rv = nsComponentManager::CreateInstance( kSoftwareUpdateCID, - nsnull, - kISoftwareUpdateIID, - (void**) &softwareUpdate); + nsresult rv = nsServiceManager::GetService( kSoftwareUpdateCID, + kISoftwareUpdateIID, + (nsISupports**)&softwareUpdate); nsIXPInstallProgressNotifier *notifier; diff --git a/xpinstall/src/nsSoftwareUpdateStream.cpp b/xpinstall/src/nsSoftwareUpdateStream.cpp index a25f10543092..29e871721a9d 100644 --- a/xpinstall/src/nsSoftwareUpdateStream.cpp +++ b/xpinstall/src/nsSoftwareUpdateStream.cpp @@ -23,7 +23,7 @@ #include "nsVector.h" #include "nsISupports.h" -#include "nsIComponentManager.h" +#include "nsIServiceManager.h" #include "nsIURL.h" #include "nsINetlibURL.h" @@ -51,10 +51,9 @@ nsSoftwareUpdateListener::nsSoftwareUpdateListener(nsInstallInfo *nextInstall) mResult = -1; }; - mResult = nsComponentManager::CreateInstance( kSoftwareUpdateCID, - nsnull, - kISoftwareUpdateIID, - (void**) &mSoftwareUpdate); + mResult = nsServiceManager::GetService( kSoftwareUpdateCID, + kISoftwareUpdateIID, + (nsISupports**)&mSoftwareUpdate); if (NS_FAILED(mResult)) return;