зеркало из https://github.com/mozilla/pjs.git
New and improved
This commit is contained in:
Родитель
8a7b1908cb
Коммит
27b6e2dbf3
|
@ -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<nsIAppShellService>( 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<nsIServiceManager> 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<nsIServiceManager> 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 )
|
||||
|
|
|
@ -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<nsIAppShellService> mAppShell;
|
||||
nsString mLastSearchString;
|
||||
PRBool mLastIgnoreCase;
|
||||
PRBool mLastSearchBackwards;
|
||||
PRBool mLastWrapSearch;
|
||||
nsInstanceCounter mInstanceCounter;
|
||||
}; // nsFindComponent
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef __nsIAppShellComponent_h
|
||||
#define __nsIAppShellComponent_h
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIAppShellService;
|
||||
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_CLASSNAME "Mozilla AppShell Component"
|
||||
|
||||
/*--------------------------- nsIAppShellComponent -----------------------------
|
||||
| This interface describes the fundamental communications between the |
|
||||
| application shell and its dynamically installable "components." Components |
|
||||
| are self-contained bits of browser client application functionality. They |
|
||||
| range in size from the general-purpose "Find dialog" up to the "browser." |
|
||||
| |
|
||||
| The interface has three main purposes: |
|
||||
| o It provides a means for the app shell to identify and load components |
|
||||
| dynamically. |
|
||||
| o It enables those components to contribute to the browser client |
|
||||
| application User Interface (e.g., by adding menu options, etc.). |
|
||||
| o It gives the app shell (and other components) a way to broadcast |
|
||||
| interesting events to other components. |
|
||||
| |
|
||||
| [Currently, only the first purpose is exploited.] |
|
||||
| |
|
||||
| All app shell components must: |
|
||||
| 1. Implement this interface. |
|
||||
| 2. Publish and implement additional interfaces, as necessary, to |
|
||||
| support component-specific function. For example, the "find |
|
||||
| component" also implements the nsIFindComponent interface which |
|
||||
| adds functions specific to that component. |
|
||||
| 3. Register (using the Mozilla XPCOM component registration facilities) |
|
||||
| using a ProgID of the form: |
|
||||
| component://netscape/appshell/component/foo |
|
||||
| where "foo" is a component-specific identifier (which should match the |
|
||||
| component-specific interface name). |
|
||||
| |
|
||||
| The app shell will instantiate each such component at application start-up |
|
||||
| and invoke the components Initialize() member function, passing a pointer |
|
||||
| to the app shell and to the command-line service corresponding to the |
|
||||
| command-line arguments used to start the app shell. |
|
||||
| |
|
||||
| The component should implement this function as necessary. Typically, a |
|
||||
| component will register interest in an appropriate set of events (e.g., |
|
||||
| browser windows opening). Some components, such as the browser, will |
|
||||
| examine the command line argements and open windows. |
|
||||
| |
|
||||
| Upon return, the app shell will maintain a reference to the component and |
|
||||
| notify it when events of interest occur. |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct nsIAppShellComponent : public nsISupports {
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR( NS_IAPPSHELLCOMPONENT_IID )
|
||||
|
||||
/*------------------------------ Initialize --------------------------------
|
||||
| Called at application startup. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Initialize( nsIAppShellService *appShell,
|
||||
nsICmdLineService *args ) = 0;
|
||||
|
||||
/*------------------------- HandleAppShellEvent ----------------------------
|
||||
| This function is called (by the app shell, when its |
|
||||
| BroadcastAppShellEvent member function is called) to broadcast |
|
||||
| application shell events that might be of interest to other components. |
|
||||
| |
|
||||
| aComponent is the ProgID of the component that generated the event. |
|
||||
| |
|
||||
| anEvent is an event code (defined by that component; should be a |
|
||||
| constant declared in that component's interface declaration). |
|
||||
| |
|
||||
| eventData is an arbitrary interface pointer that is component-defined |
|
||||
| event data. Implementors of this function must QueryInterface to |
|
||||
| convert this interface pointer to the component/event specific |
|
||||
| interface. |
|
||||
--------------------------------------------------------------------------*/
|
||||
//NS_IMETHOD HandleAppShellEvent( const char *aComponent,
|
||||
// int anEvent,
|
||||
// nsISupports *eventData );
|
||||
}; // nsIAppShellComponent
|
||||
|
||||
#define NS_DECL_IAPPSHELLCOMPONENT \
|
||||
NS_IMETHOD Initialize( nsIAppShellService *appShell, \
|
||||
nsICmdLineService *args );
|
||||
|
||||
#endif
|
|
@ -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<nsIServiceManager> 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" ); \
|
||||
|
|
|
@ -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<nsIAppShellService> 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,
|
||||
|
|
|
@ -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<nsIAppShellService> 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<nsIAppShellService>( 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 );
|
||||
}
|
||||
|
|
|
@ -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<nsIAppShellService> 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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче