From 0fc6a66d09848b706802be87eeac1a5eecd62f21 Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Thu, 13 May 1999 05:38:38 +0000 Subject: [PATCH] New and improved --- xpfe/components/find/src/nsFindComponent.cpp | 263 +----------------- xpfe/components/find/src/nsFindComponent.h | 6 +- xpfe/components/public/nsIAppShellComponent.h | 14 +- .../public/nsIAppShellComponentImpl.h | 87 +++++- .../sample/src/nsSampleAppShellComponent.cpp | 12 +- .../ucth/src/nsUnknownContentTypeHandler.cpp | 40 +-- xpfe/components/xfer/src/nsStreamTransfer.cpp | 13 +- 7 files changed, 103 insertions(+), 332 deletions(-) diff --git a/xpfe/components/find/src/nsFindComponent.cpp b/xpfe/components/find/src/nsFindComponent.cpp index 11f7735cb96d..987e921bceec 100644 --- a/xpfe/components/find/src/nsFindComponent.cpp +++ b/xpfe/components/find/src/nsFindComponent.cpp @@ -45,8 +45,7 @@ // ctor nsFindComponent::nsFindComponent() - : mAppShell(), - mLastSearchString(), + : mLastSearchString(), mLastIgnoreCase( PR_FALSE ), mLastSearchBackwards( PR_FALSE ), mLastWrapSearch( PR_FALSE ) @@ -61,53 +60,6 @@ nsFindComponent::~nsFindComponent() { } -// nsISupports Implementation -NS_IMPL_ADDREF( nsFindComponent ); -NS_IMPL_RELEASE( nsFindComponent ); - -NS_IMETHODIMP -nsFindComponent::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( nsIFindComponent::GetIID() ) ) { - *anInstancePtr = (void*) this; - NS_ADDREF_THIS(); - } else if ( anIID.Equals( nsIAppShellComponent::GetIID() ) ) { - *anInstancePtr = (void*) ( (nsIAppShellComponent*)this ); - NS_ADDREF_THIS(); - } else if ( anIID.Equals( nsISupports::GetIID() ) ) { - *anInstancePtr = (void*) ( (nsISupports*)this ); - NS_ADDREF_THIS(); - } else { - // Not an interface we support. - rv = NS_NOINTERFACE; - } - } - - return rv; -} - -NS_IMETHODIMP -nsFindComponent::Initialize( nsIAppShellService *appShell, - nsICmdLineService *args ) -{ - nsresult rv = NS_OK; - - // Remember the app shell service in case we need it. - mAppShell = nsDontQueryInterface( appShell ); - - return rv; -} - NS_IMETHODIMP nsFindComponent::CreateContext( nsIWebShell *aWebShell, nsISupports **aResult ) @@ -630,215 +582,4 @@ nsFindComponent::ResetContext( nsISupports *aContext, // nsFindComponent::Context implementation... NS_IMPL_ISUPPORTS( nsFindComponent::Context, nsISupports::GetIID() ) - -static PRInt32 g_InstanceCount = 0; -static PRInt32 g_LockCount = 0; - -// Factory stuff -struct nsFindComponentFactory : public nsIFactory { - // ctor/dtor - nsFindComponentFactory() { - NS_INIT_REFCNT(); - } - virtual ~nsFindComponentFactory() { - } - - // This class implements the nsISupports interface functions. - NS_DECL_ISUPPORTS - - // nsIFactory methods - NS_IMETHOD CreateInstance( nsISupports *aOuter, - const nsIID &aIID, - void **aResult ); - NS_IMETHOD LockFactory( PRBool aLock ); -}; - -// nsISupports interface implementation. -NS_IMPL_ADDREF(nsFindComponentFactory) -NS_IMPL_RELEASE(nsFindComponentFactory) -NS_IMETHODIMP -nsFindComponentFactory::QueryInterface( const nsIID &anIID, void **aResult ) { - nsresult rv = NS_OK; - - if ( aResult ) { - *aResult = 0; - if ( 0 ) { - } else if ( anIID.Equals( nsIFactory::GetIID() ) ) { - *aResult = (void*) (nsIFactory*)this; - NS_ADDREF_THIS(); - } else if ( anIID.Equals( nsISupports::GetIID() ) ) { - *aResult = (void*) (nsISupports*)this; - NS_ADDREF_THIS(); - } else { - rv = NS_ERROR_NO_INTERFACE; - } - } else { - rv = NS_ERROR_NULL_POINTER; - } - - return rv; -} - -NS_IMETHODIMP -nsFindComponentFactory::CreateInstance( nsISupports *anOuter, - const nsIID &anIID, - void* *aResult ) { - nsresult rv = NS_OK; - - if ( aResult ) { - // Allocate new find component object. - nsFindComponent *component = new nsFindComponent(); - - if ( component ) { - // Allocated OK, do query interface to get proper - // pointer and increment refcount. - rv = component->QueryInterface( anIID, aResult ); - if ( NS_FAILED( rv ) ) { - // refcount still at zero, delete it here. - delete component; - } - } else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } else { - rv = NS_ERROR_NULL_POINTER; - } - - return rv; -} - -NS_IMETHODIMP -nsFindComponentFactory::LockFactory(PRBool aLock) { - if (aLock) - PR_AtomicIncrement(&g_LockCount); - else - PR_AtomicDecrement(&g_LockCount); - - return NS_OK; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -extern "C" NS_EXPORT nsresult -NSRegisterSelf( nsISupports* aServiceMgr, const char* path ) { - nsresult rv = NS_OK; - - nsCOMPtr serviceMgr( do_QueryInterface( aServiceMgr, &rv ) ); - - if ( NS_SUCCEEDED( rv ) ) { - // Get the component manager service. - nsCID cid = NS_COMPONENTMANAGER_CID; - nsIComponentManager *componentMgr = 0; - rv = serviceMgr->GetService( cid, - nsIComponentManager::GetIID(), - (nsISupports**)&componentMgr ); - if ( NS_SUCCEEDED( rv ) ) { - // Register our component. - rv = componentMgr->RegisterComponent( nsFindComponent::GetCID(), - NS_IFINDCOMPONENT_CLASSNAME, - NS_IFINDCOMPONENT_PROGID, - path, - PR_TRUE, - PR_TRUE ); - - #ifdef NS_DEBUG - if ( NS_SUCCEEDED( rv ) ) { - printf( "nsFindComponent's NSRegisterSelf successful\n" ); - } else { - printf( "nsFindComponent's NSRegisterSelf failed, RegisterComponent rv=0x%X\n", (int)rv ); - } - #endif - - // Release the component manager service. - serviceMgr->ReleaseService( cid, componentMgr ); - } else { - #ifdef NS_DEBUG - printf( "nsFindComponent's NSRegisterSelf failed, GetService rv=0x%X\n", (int)rv ); - #endif - } - } else { - #ifdef NS_DEBUG - printf( "nsFindComponent's NSRegisterSelf failed, QueryInterface rv=0x%X\n", (int)rv ); - #endif - } - - return rv; -} - -extern "C" NS_EXPORT nsresult -NSUnregisterSelf( nsISupports* aServiceMgr, const char* path ) { - nsresult rv = NS_OK; - - nsCOMPtr serviceMgr( do_QueryInterface( aServiceMgr, &rv ) ); - - if ( NS_SUCCEEDED( rv ) ) { - // Get the component manager service. - nsCID cid = NS_COMPONENTMANAGER_CID; - nsIComponentManager *componentMgr = 0; - rv = serviceMgr->GetService( cid, - nsIComponentManager::GetIID(), - (nsISupports**)&componentMgr ); - if ( NS_SUCCEEDED( rv ) ) { - // Register our component. - rv = componentMgr->UnregisterComponent( nsFindComponent::GetCID(), path ); - - #ifdef NS_DEBUG - if ( NS_SUCCEEDED( rv ) ) { - printf( "nsFindComponent's NSUnregisterSelf successful\n" ); - } else { - printf( "nsFindComponent's NSUnregisterSelf failed, UnregisterComponent rv=0x%X\n", (int)rv ); - } - #endif - - // Release the component manager service. - serviceMgr->ReleaseService( cid, componentMgr ); - } else { - #ifdef NS_DEBUG - printf( "nsFindComponent's NSRegisterSelf failed, GetService rv=0x%X\n", (int)rv ); - #endif - } - } else { - #ifdef NS_DEBUG - printf( "nsFindComponent's NSRegisterSelf failed, QueryInterface rv=0x%X\n", (int)rv ); - #endif - } - - return rv; -} - -extern "C" NS_EXPORT nsresult -NSGetFactory( nsISupports *aServMgr, - const nsCID &aClass, - const char *aClassName, - const char *aProgID, - nsIFactory* *aFactory ) { - nsresult rv = NS_OK; - - if ( aFactory ) { - nsFindComponentFactory *factory = new nsFindComponentFactory(); - if ( factory ) { - rv = factory->QueryInterface( nsIFactory::GetIID(), (void**)aFactory ); - if ( NS_FAILED( rv ) ) { - #ifdef NS_DEBUG - printf( "nsFindComponent's NSGetFactory failed, QueryInterface rv=0x%X\n", (int)rv ); - #endif - // Delete this bogus factory. - delete factory; - } - } else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } else { - rv = NS_ERROR_NULL_POINTER; - } - - return rv; -} - -extern "C" NS_EXPORT PRBool -NSCanUnload( nsISupports* aServiceMgr ) { - PRBool result = g_InstanceCount == 0 && g_LockCount == 0; - return result; -} +NS_IMPL_IAPPSHELLCOMPONENT( nsFindComponent, nsIFindComponent, NS_IFINDCOMPONENT_PROGID ) diff --git a/xpfe/components/find/src/nsFindComponent.h b/xpfe/components/find/src/nsFindComponent.h index c3b1c702f115..e5d16b7e9558 100644 --- a/xpfe/components/find/src/nsFindComponent.h +++ b/xpfe/components/find/src/nsFindComponent.h @@ -15,7 +15,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ - +#include "nsIAppShellComponentImpl.h" class nsITextServicesDocument; @@ -23,7 +23,7 @@ class nsITextServicesDocument; #define NS_FINDCOMPONENT_CID \ { 0x4aa267a0, 0xf81d, 0x11d2, { 0x80, 0x67, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3} } -class nsFindComponent : public nsIFindComponent +class nsFindComponent : public nsIFindComponent, public nsAppShellComponentImpl { public: NS_DEFINE_STATIC_CID_ACCESSOR( NS_FINDCOMPONENT_CID ); @@ -74,9 +74,9 @@ public: }; // nsFindComponent::Context protected: - nsCOMPtr mAppShell; nsString mLastSearchString; PRBool mLastIgnoreCase; PRBool mLastSearchBackwards; PRBool mLastWrapSearch; + nsInstanceCounter mInstanceCounter; }; // nsFindComponent diff --git a/xpfe/components/public/nsIAppShellComponent.h b/xpfe/components/public/nsIAppShellComponent.h index 8eea31bd63f3..8ebeff42bb64 100644 --- a/xpfe/components/public/nsIAppShellComponent.h +++ b/xpfe/components/public/nsIAppShellComponent.h @@ -26,8 +26,9 @@ class nsICmdLineService; // a6cf90ed-15b3-11d2-932e-00805f8add32 #define NS_IAPPSHELLCOMPONENT_IID \ { 0xa6cf90ed, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }; -#define NS_IAPPSHELLCOMPONENT_PROGID "component://netscape/appshell/component" +#define NS_IAPPSHELLCOMPONENT_PROGID "component://netscape/appshell/component" #define NS_IAPPSHELLCOMPONENT_CLASSNAME "Mozilla AppShell Component" +#define NS_IAPPSHELLCOMPONENT_KEY "software/netscape/appshell/components" /*--------------------------- nsIAppShellComponent ----------------------------- | This interface describes the fundamental communications between the | @@ -79,6 +80,12 @@ struct nsIAppShellComponent : public nsISupports { NS_IMETHOD Initialize( nsIAppShellService *appShell, nsICmdLineService *args ) = 0; + /*------------------------------- Shutdown --------------------------------- + | Called at application shutdown (if the component had registered as a | + | service). | + --------------------------------------------------------------------------*/ + NS_IMETHOD Shutdown() = 0; + /*------------------------- HandleAppShellEvent ---------------------------- | This function is called (by the app shell, when its | | BroadcastAppShellEvent member function is called) to broadcast | @@ -100,7 +107,8 @@ struct nsIAppShellComponent : public nsISupports { }; // nsIAppShellComponent #define NS_DECL_IAPPSHELLCOMPONENT \ - NS_IMETHOD Initialize( nsIAppShellService *appShell, \ - nsICmdLineService *args ); + NS_IMETHOD Initialize( nsIAppShellService*, \ + nsICmdLineService* ); \ + NS_IMETHOD Shutdown(); #endif diff --git a/xpfe/components/public/nsIAppShellComponentImpl.h b/xpfe/components/public/nsIAppShellComponentImpl.h index 5f256b3c7c83..d9a110f86643 100644 --- a/xpfe/components/public/nsIAppShellComponentImpl.h +++ b/xpfe/components/public/nsIAppShellComponentImpl.h @@ -26,11 +26,10 @@ #include "nsICmdLineService.h" #include "nsISupports.h" #include "nsIFactory.h" +#include "nsIRegistry.h" #include "pratom.h" #include "nsCOMPtr.h" -#ifdef NS_DEBUG #include "prprf.h" -#endif /*------------------------------------------------------------------------------ | This file contains macros to assist in the implementation of application | @@ -86,9 +85,49 @@ private: PRInt32 nsInstanceCounter::mInstanceCount = 0; \ PRInt32 nsInstanceCounter::mLockCount = 0; +// Declare component-global class. +class nsAppShellComponentImpl { +public: + // Override this and return PR_FALSE if your component + // should not be registered with the Service Manager + // when Initialize-d. + virtual PRBool Is_Service() { return PR_TRUE; } + static nsIServiceManager *mServiceMgr; + static nsIAppShellService *mAppShell; + static nsICmdLineService *mCmdLine; +}; // nsAppShellComponent + +#define NS_DEFINE_COMPONENT_GLOBALS() \ +nsIServiceManager *nsAppShellComponentImpl::mServiceMgr = 0; \ +nsIAppShellService *nsAppShellComponentImpl::mAppShell = 0; \ +nsICmdLineService *nsAppShellComponentImpl::mCmdLine = 0; + #define NS_IMPL_IAPPSHELLCOMPONENT( className, interfaceName, progId ) \ /* Define instance counter implementation stuff. */\ NS_DEFINE_MODULE_INSTANCE_COUNTER() \ +/* Define component globals. */\ +NS_DEFINE_COMPONENT_GLOBALS() \ +/* Component's implementation of Initialize. */\ +NS_IMETHODIMP \ +className::Initialize( nsIAppShellService *anAppShell, \ + nsICmdLineService *aCmdLineService ) { \ + nsresult rv = NS_OK; \ + mAppShell = anAppShell; \ + mCmdLine = aCmdLineService; \ + if ( mServiceMgr && Is_Service() ) { \ + rv = mServiceMgr->RegisterService( progId, this ); \ + } \ + return rv; \ +} \ +/* Component's implementation of Shutdown. */\ +NS_IMETHODIMP \ +className::Shutdown() { \ + nsresult rv = NS_OK; \ + if ( mServiceMgr && Is_Service() ) { \ + rv = mServiceMgr->ReleaseService( progId, this ); \ + } \ + return rv; \ +} \ /* nsISupports Implementation for the class */\ NS_IMPL_ADDREF( className ); \ NS_IMPL_RELEASE( className ); \ @@ -195,14 +234,16 @@ className##Factory::LockFactory(PRBool aLock) { \ extern "C" NS_EXPORT nsresult \ NSRegisterSelf( nsISupports* aServiceMgr, const char* path ) { \ nsresult rv = NS_OK; \ - nsCOMPtr serviceMgr( do_QueryInterface( aServiceMgr, &rv ) ); \ + /* Remember service manager. */\ + rv = aServiceMgr->QueryInterface( nsIServiceManager::GetIID(), \ + (void**)&className::mServiceMgr ); \ if ( NS_SUCCEEDED( rv ) ) { \ /* Get the component manager service. */\ nsCID cid = NS_COMPONENTMANAGER_CID; \ nsIComponentManager *componentMgr = 0; \ - rv = serviceMgr->GetService( cid, \ - nsIComponentManager::GetIID(), \ - (nsISupports**)&componentMgr ); \ + rv = className::mServiceMgr->GetService( cid, \ + nsIComponentManager::GetIID(), \ + (nsISupports**)&componentMgr ); \ if ( NS_SUCCEEDED( rv ) ) { \ /* Register our component. */\ rv = componentMgr->RegisterComponent( className::GetCID(), \ @@ -212,12 +253,40 @@ NSRegisterSelf( nsISupports* aServiceMgr, const char* path ) { \ PR_TRUE, \ PR_TRUE ); \ if ( NS_SUCCEEDED( rv ) ) { \ - DEBUG_PRINTF( PR_STDOUT, #className " registeration successful\n" ); \ + DEBUG_PRINTF( PR_STDOUT, #className " registration successful\n" ); \ + /* Add to appshell component list. */\ + nsIRegistry *registry; \ + rv = className::mServiceMgr->GetService( NS_REGISTRY_PROGID, \ + nsIRegistry::GetIID(), \ + (nsISupports**)®istry ); \ + if ( NS_SUCCEEDED( rv ) ) { \ + registry->Open(); \ + char buffer[256]; \ + char *cid = className::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 ); \ + if ( NS_SUCCEEDED( rv ) ) { \ + DEBUG_PRINTF( PR_STDOUT, #className " added to appshell component list\n" ); \ + } else { \ + DEBUG_PRINTF( PR_STDOUT, #className " not added to appshell component list, rv=0x%X\n", (int)rv ); \ + } \ + className::mServiceMgr->ReleaseService( NS_REGISTRY_PROGID, registry ); \ + } else { \ + DEBUG_PRINTF( PR_STDOUT, #className " not added to appshell component list, rv=0x%X\n", (int)rv ); \ + } \ } else { \ DEBUG_PRINTF( PR_STDOUT, #className " registration failed, RegisterComponent rv=0x%X\n", (int)rv ); \ } \ /* Release the component manager service. */\ - serviceMgr->ReleaseService( cid, componentMgr ); \ + className::mServiceMgr->ReleaseService( cid, componentMgr ); \ } else { \ DEBUG_PRINTF( PR_STDOUT, #className " registration failed, GetService rv=0x%X\n", (int)rv ); \ } \ @@ -239,7 +308,7 @@ NSUnregisterSelf( nsISupports* aServiceMgr, const char* path ) { \ nsIComponentManager::GetIID(), \ (nsISupports**)&componentMgr ); \ if ( NS_SUCCEEDED( rv ) ) { \ - /* Register our component. */\ + /* Unregister our component. */\ rv = componentMgr->UnregisterComponent( className::GetCID(), path ); \ if ( NS_SUCCEEDED( rv ) ) { \ DEBUG_PRINTF( PR_STDOUT, #className " unregistration successful\n" ); \ diff --git a/xpfe/components/sample/src/nsSampleAppShellComponent.cpp b/xpfe/components/sample/src/nsSampleAppShellComponent.cpp index bcdb9106c460..949267544f88 100644 --- a/xpfe/components/sample/src/nsSampleAppShellComponent.cpp +++ b/xpfe/components/sample/src/nsSampleAppShellComponent.cpp @@ -49,7 +49,8 @@ { 0xcfc599f0, 0x4ca, 0x11d3, { 0x80, 0x68, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } } // Implementation of the sample app shell component interface. -class nsSampleAppShellComponent : public nsISampleAppShellComponent { +class nsSampleAppShellComponent : public nsISampleAppShellComponent, + public nsAppShellComponentImpl { public: NS_DEFINE_STATIC_CID_ACCESSOR( NS_SAMPLEAPPSHELLCOMPONENT_CID ); @@ -71,7 +72,6 @@ public: private: // Data members and implemention functions go here. - nsCOMPtr mAppShell; // Objects of this class are counted to manage library unloading... nsInstanceCounter instanceCounter; @@ -85,14 +85,6 @@ nsSampleAppShellComponent::DoDialogTests() { return rv; } -NS_IMETHODIMP -nsSampleAppShellComponent::Initialize( nsIAppShellService *anAppShell, - nsICmdLineService *aCmdLineService ) { - nsresult rv = NS_OK; - mAppShell = dont_QueryInterface( anAppShell ); - return rv; -} - // Generate base nsIAppShellComponent implementation. NS_IMPL_IAPPSHELLCOMPONENT( nsSampleAppShellComponent, nsISampleAppShellComponent, diff --git a/xpfe/components/ucth/src/nsUnknownContentTypeHandler.cpp b/xpfe/components/ucth/src/nsUnknownContentTypeHandler.cpp index d690d0d87406..0fc8fcb70bac 100644 --- a/xpfe/components/ucth/src/nsUnknownContentTypeHandler.cpp +++ b/xpfe/components/ucth/src/nsUnknownContentTypeHandler.cpp @@ -39,7 +39,8 @@ #define NS_UNKNOWNCONTENTTYPEHANDLER_CID \ { 0x42770b50, 0x3e9, 0x11d3, { 0x80, 0x68, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } } -class nsUnknownContentTypeHandler : public nsIUnknownContentTypeHandler { +class nsUnknownContentTypeHandler : public nsIUnknownContentTypeHandler, + public nsAppShellComponentImpl { public: NS_DEFINE_STATIC_CID_ACCESSOR( NS_UNKNOWNCONTENTTYPEHANDLER_CID ); @@ -60,23 +61,9 @@ public: NS_DECL_IUNKNOWNCONTENTTYPEHANDLER private: - nsCOMPtr mAppShell; nsInstanceCounter mInstanceCounter; }; // nsUnknownContentTypeHandler -// Initialize (from nsIAppShellComponent) implementation. -NS_IMETHODIMP -nsUnknownContentTypeHandler::Initialize( nsIAppShellService *appShell, - nsICmdLineService *args ) -{ - nsresult rv = NS_OK; - - // Remember the app shell service in case we need it. - mAppShell = nsDontQueryInterface( appShell ); - - return rv; -} - struct nsUnknownContentDialog : public nsIXULWindowCallbacks, nsIDocumentObserver { // Declare implementation of ISupports stuff. @@ -355,27 +342,11 @@ nsUnknownContentDialog::OnSave() { // Get "stream xfer component". nsIStreamTransfer *xfer; - rv = nsServiceManager::GetService( NS_ISTREAMTRANSFER_PROGID, - nsIStreamTransfer::GetIID(), - (nsISupports**)&xfer ); + rv = nsAppShellComponentImpl::mServiceMgr->GetService( NS_ISTREAMTRANSFER_PROGID, + nsIStreamTransfer::GetIID(), + (nsISupports**)&xfer ); if ( NS_SUCCEEDED( rv ) ) { - #if 1 - // Temporary code pending proper component initialization in apprunner main. - static PRBool initialized = PR_FALSE; - if ( !initialized ) { - // Get app shell service. - nsIAppShellService *appShell; - rv = nsServiceManager::GetService( kAppShellServiceCID, - nsIAppShellService::GetIID(), - (nsISupports**)&appShell ); - if ( NS_SUCCEEDED( rv ) ) { - rv = xfer->Initialize( appShell, 0 ); - nsServiceManager::ReleaseService( kAppShellServiceCID, appShell ); - initialized = PR_TRUE; - } - } - #endif // Have the component stream the url to a user-selected file. rv = xfer->SelectFileAndTransferLocation( mUrl ); @@ -386,6 +357,7 @@ nsUnknownContentDialog::OnSave() { DEBUG_PRINTF( PR_STDOUT, "%s %d: Error saving file, rv=0x%X\n", __FILE__, (int)__LINE__, (int)rv ); } + nsAppShellComponentImpl::mServiceMgr->ReleaseService( NS_ISTREAMTRANSFER_PROGID, xfer ); } else { DEBUG_PRINTF( PR_STDOUT, "Unable to get stream transfer, GetService rv=0x%X\n", (int)rv ); } diff --git a/xpfe/components/xfer/src/nsStreamTransfer.cpp b/xpfe/components/xfer/src/nsStreamTransfer.cpp index a2e1a9e6cd9d..819c8ffd8c90 100644 --- a/xpfe/components/xfer/src/nsStreamTransfer.cpp +++ b/xpfe/components/xfer/src/nsStreamTransfer.cpp @@ -30,7 +30,7 @@ static NS_DEFINE_IID( kCFileWidgetCID, NS_FILEWIDGET_CID ); static NS_DEFINE_IID( kIFileWidgetIID, NS_IFILEWIDGET_IID ); // Implementation of the stream transfer component interface. -class nsStreamTransfer : public nsIStreamTransfer { +class nsStreamTransfer : public nsIStreamTransfer, public nsAppShellComponentImpl { public: NS_DEFINE_STATIC_CID_ACCESSOR( NS_STREAMTRANSFER_CID ); @@ -54,21 +54,10 @@ private: // Put up file picker dialog. NS_IMETHOD SelectFile( nsFileSpec &result ); - // Hold reference to app shell service (for OpenWindow calls). - nsCOMPtr mAppShell; - // Objects of this class are counted to manage library unloading... nsInstanceCounter instanceCounter; }; // nsStreamTransfer -NS_IMETHODIMP -nsStreamTransfer::Initialize( nsIAppShellService *anAppShell, - nsICmdLineService *aCmdLineService ) { - nsresult rv = NS_OK; - mAppShell = dont_QueryInterface( anAppShell ); - return rv; -} - NS_IMETHODIMP nsStreamTransfer::SelectFileAndTransferLocation( nsIURL *aURL ) { // Prompt the user for the destination file.