1998-12-03 04:35:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-12-03 04:35:53 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-12-03 04:35:53 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:43:54 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-01 17:26:27 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1998-12-03 04:35:53 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsISupportsArray.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsIURL.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-01-21 10:22:58 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
1999-10-22 01:36:25 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIObserver.h"
|
1999-12-07 17:06:36 +03:00
|
|
|
#include "nsWeakReference.h"
|
1999-01-21 10:22:58 +03:00
|
|
|
#include "nsXPComFactory.h" /* template implementation of a XPCOM factory */
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-08-10 02:28:30 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
1999-07-27 10:34:25 +04:00
|
|
|
#include "nsIBrowserWindow.h"
|
1999-02-17 19:12:10 +03:00
|
|
|
#include "nsIWebShellWindow.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsWebShellWindow.h"
|
|
|
|
|
1999-05-15 02:02:23 +04:00
|
|
|
#include "nsIAppShellComponent.h"
|
|
|
|
#include "nsIRegistry.h"
|
|
|
|
#include "nsIEnumerator.h"
|
|
|
|
#include "nsICmdLineService.h"
|
1999-05-27 09:12:12 +04:00
|
|
|
#include "nsCRT.h"
|
1999-05-15 02:02:23 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "prprf.h"
|
|
|
|
#endif
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-02-10 19:38:51 +03:00
|
|
|
#include "nsIStreamObserver.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-02-04 21:17:02 +03:00
|
|
|
#ifdef MOZ_FULLCIRCLE
|
|
|
|
#include "fullsoft.h"
|
|
|
|
#endif
|
|
|
|
|
1999-05-18 05:44:51 +04:00
|
|
|
#include "nsMetaCharsetCID.h"
|
|
|
|
#include "nsIMetaCharsetService.h"
|
|
|
|
|
1999-10-08 18:04:17 +04:00
|
|
|
/* For implementing GetHiddenWindowAndJSContext */
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2000-02-05 08:38:13 +03:00
|
|
|
#include "nsAppShellService.h"
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
/* Define Class IDs */
|
2000-02-01 02:45:42 +03:00
|
|
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-05-19 07:03:48 +04:00
|
|
|
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
|
2000-02-01 02:45:42 +03:00
|
|
|
static NS_DEFINE_CID(kMetaCharsetCID, NS_META_CHARSET_CID);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
1999-10-22 01:36:25 +04:00
|
|
|
// copied from nsEventQueue.cpp
|
|
|
|
static char *gEQActivatedNotification = "nsIEventQueueActivated";
|
|
|
|
static char *gEQDestroyedNotification = "nsIEventQueueDestroyed";
|
|
|
|
|
2000-02-22 09:01:57 +03:00
|
|
|
nsAppShellService::nsAppShellService() : mWindowMediator( NULL ), mShuttingDown( PR_FALSE )
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mAppShell = nsnull;
|
|
|
|
mWindowList = nsnull;
|
1999-05-15 02:02:23 +04:00
|
|
|
mCmdLineService = nsnull;
|
1999-09-11 10:25:51 +04:00
|
|
|
mDeleteCalled = PR_FALSE;
|
2000-02-04 17:40:08 +03:00
|
|
|
mSplashScreen = nsnull;
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShellService::~nsAppShellService()
|
|
|
|
{
|
1999-09-11 10:25:51 +04:00
|
|
|
mDeleteCalled = PR_TRUE;
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IF_RELEASE(mAppShell);
|
|
|
|
NS_IF_RELEASE(mWindowList);
|
1999-05-15 02:02:23 +04:00
|
|
|
NS_IF_RELEASE(mCmdLineService);
|
2000-02-04 17:40:08 +03:00
|
|
|
NS_IF_RELEASE(mSplashScreen);
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIWebShellWindow> hiddenWin(do_QueryInterface(mHiddenWindow));
|
|
|
|
if(hiddenWin)
|
|
|
|
hiddenWin->Close();
|
|
|
|
|
|
|
|
hiddenWin = nsnull;
|
|
|
|
mHiddenWindow = nsnull;
|
|
|
|
|
|
|
|
mWindowMediator = nsnull;
|
1999-11-02 04:10:35 +03:00
|
|
|
/* Note we don't unregister with the observer service
|
|
|
|
(RegisterObserver(PR_FALSE)) because, being refcounted, we can't have
|
|
|
|
reached our own destructor until after the ObserverService has shut down
|
|
|
|
and released us. This means we leak until the end of the application, but
|
|
|
|
so what; this is the appshell service. */
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement the nsISupports methods...
|
|
|
|
*/
|
1999-12-07 17:06:36 +03:00
|
|
|
NS_IMPL_ADDREF(nsAppShellService)
|
|
|
|
NS_IMPL_RELEASE(nsAppShellService)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsAppShellService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAppShellService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAppShellService)
|
|
|
|
NS_INTERFACE_MAP_END
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-02-04 17:40:08 +03:00
|
|
|
nsAppShellService::Initialize( nsICmdLineService *aCmdLineService,
|
|
|
|
nsISplashScreen *aSplashScreen )
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-02-04 21:17:02 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_FULLCIRCLE
|
1999-02-05 01:57:13 +03:00
|
|
|
FCInitialize();
|
1999-02-04 21:17:02 +03:00
|
|
|
#endif
|
1999-06-11 07:44:52 +04:00
|
|
|
|
1999-05-15 02:02:23 +04:00
|
|
|
// Remember cmd line service.
|
|
|
|
mCmdLineService = aCmdLineService;
|
|
|
|
NS_IF_ADDREF( mCmdLineService );
|
|
|
|
|
2000-02-04 17:40:08 +03:00
|
|
|
// Remember the splash screen.
|
|
|
|
mSplashScreen = aSplashScreen;
|
|
|
|
NS_IF_ADDREF( mSplashScreen );
|
|
|
|
|
1999-01-21 10:22:58 +03:00
|
|
|
// Create the Event Queue for the UI thread...
|
1999-03-19 09:15:00 +03:00
|
|
|
nsIEventQueueService* eventQService;
|
1999-01-21 10:22:58 +03:00
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
2000-02-01 02:45:42 +03:00
|
|
|
NS_GET_IID(nsIEventQueueService),
|
1999-03-19 09:15:00 +03:00
|
|
|
(nsISupports **)&eventQService);
|
1999-01-21 10:22:58 +03:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// XXX: What if this fails?
|
1999-03-19 09:15:00 +03:00
|
|
|
rv = eventQService->CreateThreadEventQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the toplevel window list...
|
1998-12-03 04:35:53 +03:00
|
|
|
rv = NS_NewISupportsArray(&mWindowList);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-05-18 05:44:51 +04:00
|
|
|
nsIMetaCharsetService* metacharset;
|
|
|
|
rv = nsServiceManager::GetService(kMetaCharsetCID,
|
2000-02-01 02:45:42 +03:00
|
|
|
NS_GET_IID(nsIMetaCharsetService),
|
1999-05-18 05:44:51 +04:00
|
|
|
(nsISupports **) &metacharset);
|
|
|
|
if(NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rv = metacharset->Start();
|
|
|
|
if(NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rv = nsServiceManager::ReleaseService(kMetaCharsetCID, metacharset);
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
// Create widget application shell
|
2000-02-01 02:45:42 +03:00
|
|
|
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, NS_GET_IID(nsIAppShell),
|
1998-12-03 04:35:53 +03:00
|
|
|
(void**)&mAppShell);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mAppShell->Create(0, nsnull);
|
|
|
|
|
1999-05-15 02:02:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-10-22 01:36:25 +04:00
|
|
|
// listen to EventQueues' comings and goings. do this after the appshell
|
|
|
|
// has been created, but after the event queue has been created. that
|
|
|
|
// latter bit is unfortunate, but we deal with it.
|
|
|
|
RegisterObserver(PR_TRUE);
|
1999-08-31 06:47:56 +04:00
|
|
|
|
1999-06-22 07:06:19 +04:00
|
|
|
// enable window mediation
|
2000-02-29 03:20:55 +03:00
|
|
|
mWindowMediator = do_GetService(kWindowMediatorCID);
|
1999-07-20 18:40:55 +04:00
|
|
|
|
1999-10-13 02:20:28 +04:00
|
|
|
// CreateHiddenWindow(); // rjc: now require this to be explicitly called
|
1999-07-20 18:40:55 +04:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-10-13 02:20:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::CreateHiddenWindow()
|
1999-07-20 18:40:55 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIURI* url = nsnull;
|
|
|
|
|
1999-10-08 07:31:41 +04:00
|
|
|
#if XP_MAC
|
1999-08-08 00:33:01 +04:00
|
|
|
rv = NS_NewURI(&url, "chrome://global/content/hiddenWindow.xul");
|
1999-07-20 18:40:55 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIXULWindow> newWindow;
|
1999-08-17 02:23:19 +04:00
|
|
|
rv = JustCreateTopWindow(nsnull, url, PR_FALSE, PR_FALSE,
|
1999-09-18 07:21:30 +04:00
|
|
|
0, nsnull, 0, 0,
|
|
|
|
getter_AddRefs(newWindow));
|
1999-10-08 07:31:41 +04:00
|
|
|
#else
|
|
|
|
rv = NS_NewURI(&url, "about:blank");
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIXULWindow> newWindow;
|
1999-09-18 07:21:30 +04:00
|
|
|
rv = JustCreateTopWindow(nsnull, url, PR_FALSE, PR_FALSE,
|
1999-08-17 02:23:19 +04:00
|
|
|
NS_CHROME_ALL_CHROME, nsnull, 100, 100,
|
|
|
|
getter_AddRefs(newWindow));
|
1999-10-08 07:31:41 +04:00
|
|
|
#endif
|
1999-07-20 18:40:55 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mHiddenWindow = newWindow;
|
1999-07-27 10:34:25 +04:00
|
|
|
// RegisterTopLevelWindow(newWindow); -- Mac only
|
1999-07-20 18:40:55 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(url);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "HiddenWindow not created");
|
1999-10-13 03:09:09 +04:00
|
|
|
return(rv);
|
1999-07-20 18:40:55 +04:00
|
|
|
}
|
|
|
|
|
1999-08-31 06:47:56 +04:00
|
|
|
NS_IMETHODIMP nsAppShellService::EnumerateAndInitializeComponents(void)
|
|
|
|
{
|
|
|
|
// Initialize each registered component.
|
|
|
|
EnumerateComponents( &nsAppShellService::InitializeComponent );
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-15 02:02:23 +04:00
|
|
|
// Apply function (Initialize/Shutdown) to each app shell component.
|
|
|
|
void
|
1999-06-22 21:26:26 +04:00
|
|
|
nsAppShellService::EnumerateComponents( EnumeratorMemberFunction function ) {
|
1999-05-15 02:02:23 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsIRegistry *registry = 0;
|
1999-09-29 07:26:24 +04:00
|
|
|
nsRegistryKey key;
|
1999-05-15 02:02:23 +04:00
|
|
|
nsIEnumerator *components = 0;
|
|
|
|
const char *failed = "GetService";
|
|
|
|
if ( NS_SUCCEEDED( ( rv = nsServiceManager::GetService( NS_REGISTRY_PROGID,
|
2000-02-01 17:26:27 +03:00
|
|
|
NS_GET_IID(nsIRegistry),
|
1999-05-15 02:02:23 +04:00
|
|
|
(nsISupports**)®istry ) ) )
|
|
|
|
&&
|
|
|
|
( failed = "Open" )
|
|
|
|
&&
|
1999-06-09 23:19:14 +04:00
|
|
|
NS_SUCCEEDED( ( rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry) ) )
|
1999-05-15 02:02:23 +04:00
|
|
|
&&
|
|
|
|
( failed = "GetSubtree" )
|
|
|
|
&&
|
|
|
|
NS_SUCCEEDED( ( rv = registry->GetSubtree( nsIRegistry::Common,
|
|
|
|
NS_IAPPSHELLCOMPONENT_KEY,
|
|
|
|
&key ) ) )
|
|
|
|
&&
|
|
|
|
( failed = "EnumerateSubtrees" )
|
|
|
|
&&
|
|
|
|
NS_SUCCEEDED( ( rv = registry->EnumerateSubtrees( key,
|
|
|
|
&components ) ) )
|
|
|
|
&&
|
|
|
|
( failed = "First" )
|
|
|
|
&&
|
|
|
|
NS_SUCCEEDED( ( rv = components->First() ) ) ) {
|
|
|
|
// Enumerate all subtrees
|
1999-09-21 05:28:18 +04:00
|
|
|
while ( NS_SUCCEEDED( rv ) && (NS_OK != components->IsDone()) ) {
|
1999-05-15 02:02:23 +04:00
|
|
|
nsISupports *base;
|
|
|
|
|
|
|
|
rv = components->CurrentItem( &base );
|
|
|
|
if ( NS_SUCCEEDED( rv ) ) {
|
|
|
|
// Get specific interface.
|
|
|
|
nsIRegistryNode *node;
|
|
|
|
nsIID nodeIID = NS_IREGISTRYNODE_IID;
|
|
|
|
rv = base->QueryInterface( nodeIID, (void**)&node );
|
|
|
|
// Test that result.
|
|
|
|
if ( NS_SUCCEEDED( rv ) ) {
|
|
|
|
// Get node name.
|
|
|
|
char *name;
|
2000-02-20 06:12:59 +03:00
|
|
|
rv = node->GetNameUTF8( &name );
|
1999-05-15 02:02:23 +04:00
|
|
|
if ( NS_SUCCEEDED( rv ) ) {
|
|
|
|
// If this is a CID of a component; apply function to it.
|
|
|
|
nsCID cid;
|
|
|
|
if ( cid.Parse( name ) ) {
|
|
|
|
(this->*function)( cid );
|
|
|
|
} else {
|
|
|
|
// Not a valid CID, ignore it.
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unable to get subkey name, ignore it.
|
|
|
|
}
|
|
|
|
// Release the node.
|
1999-05-27 09:12:12 +04:00
|
|
|
nsCRT::free(name);
|
1999-05-15 02:02:23 +04:00
|
|
|
NS_RELEASE( node );
|
|
|
|
} else {
|
|
|
|
// Unable to convert item to registry node, ignore it.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release the current (generic) item.
|
|
|
|
NS_RELEASE( base );
|
|
|
|
} else {
|
|
|
|
// Unable to get current item, ignore it.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go on to next component, if this fails, we quit.
|
|
|
|
rv = components->Next();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unable to set up for subkey enumeration.
|
|
|
|
#ifdef NS_DEBUG
|
1999-05-15 07:02:06 +04:00
|
|
|
printf( "Unable to enumerator app shell components, %s rv=0x%08X\n",
|
|
|
|
failed, (int)rv );
|
1999-05-15 02:02:23 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up.
|
|
|
|
if ( registry ) {
|
|
|
|
// Release enumerator (if necessary).
|
|
|
|
NS_IF_RELEASE( components );
|
|
|
|
|
|
|
|
// Release nsIRegistry service.
|
|
|
|
nsServiceManager::ReleaseService( NS_REGISTRY_PROGID, registry );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShellService::InitializeComponent( const nsCID &aComponentCID ) {
|
|
|
|
// Attempt to create instance of the component.
|
|
|
|
nsIAppShellComponent *component;
|
|
|
|
nsresult rv = nsComponentManager::CreateInstance( aComponentCID,
|
|
|
|
0,
|
2000-02-01 17:26:27 +03:00
|
|
|
NS_GET_IID(nsIAppShellComponent),
|
1999-05-15 02:02:23 +04:00
|
|
|
(void**)&component );
|
|
|
|
if ( NS_SUCCEEDED( rv ) ) {
|
|
|
|
// Then tell it to initialize (it may RegisterService itself).
|
|
|
|
rv = component->Initialize( this, mCmdLineService );
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
char *name = aComponentCID.ToString();
|
1999-05-15 07:02:06 +04:00
|
|
|
printf( "Initialized app shell component %s, rv=0x%08X\n",
|
|
|
|
name, (int)rv );
|
1999-11-16 08:07:31 +03:00
|
|
|
Recycle(name);
|
1999-05-15 02:02:23 +04:00
|
|
|
#endif
|
|
|
|
// Release it (will live on if it registered itself as service).
|
|
|
|
component->Release();
|
|
|
|
} else {
|
|
|
|
// Error creating component.
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
char *name = aComponentCID.ToString();
|
1999-05-15 07:02:06 +04:00
|
|
|
printf( "Error creating app shell component %s, rv=0x%08X\n",
|
|
|
|
name, (int)rv );
|
1999-11-16 08:07:31 +03:00
|
|
|
Recycle(name);
|
1999-05-15 02:02:23 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShellService::ShutdownComponent( const nsCID &aComponentCID ) {
|
|
|
|
// Attempt to create instance of the component (must be a service).
|
|
|
|
nsIAppShellComponent *component;
|
|
|
|
nsresult rv = nsServiceManager::GetService( aComponentCID,
|
2000-02-01 17:26:27 +03:00
|
|
|
NS_GET_IID(nsIAppShellComponent),
|
1999-05-15 02:02:23 +04:00
|
|
|
(nsISupports**)&component );
|
|
|
|
if ( NS_SUCCEEDED( rv ) ) {
|
|
|
|
// Instance accessed, tell it to shutdown.
|
|
|
|
rv = component->Shutdown();
|
1999-12-22 02:11:17 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-05-15 02:02:23 +04:00
|
|
|
char *name = aComponentCID.ToString();
|
1999-05-15 07:02:06 +04:00
|
|
|
printf( "Shut down app shell component %s, rv=0x%08X\n",
|
|
|
|
name, (int)rv );
|
1999-12-22 02:11:17 +03:00
|
|
|
nsCRT::free(name);
|
|
|
|
#endif
|
1999-05-15 02:02:23 +04:00
|
|
|
// Release the service.
|
|
|
|
nsServiceManager::ReleaseService( aComponentCID, component );
|
|
|
|
} else {
|
|
|
|
// Error getting component service (perhaps due to that component not being
|
|
|
|
// a service).
|
1999-12-22 02:11:17 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-05-15 02:02:23 +04:00
|
|
|
char *name = aComponentCID.ToString();
|
1999-05-15 07:02:06 +04:00
|
|
|
printf( "Unable to shut down app shell component %s, rv=0x%08X\n",
|
|
|
|
name, (int)rv );
|
1999-12-22 02:11:17 +03:00
|
|
|
nsCRT::free(name);
|
|
|
|
#endif
|
1999-05-15 02:02:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Run(void)
|
|
|
|
{
|
|
|
|
return mAppShell->Run();
|
|
|
|
}
|
|
|
|
|
1999-08-10 02:28:30 +04:00
|
|
|
|
1999-11-11 08:51:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Quit()
|
1999-09-17 03:42:49 +04:00
|
|
|
{
|
1999-11-11 08:51:22 +03:00
|
|
|
// Quit the application. We will asynchronously call the appshell's
|
|
|
|
// Exit() method via the ExitCallback() to allow one last pass
|
|
|
|
// through any events in the queue. This guarantees a tidy cleanup.
|
2000-02-22 09:01:57 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-11 08:51:22 +03:00
|
|
|
|
2000-02-22 09:01:57 +03:00
|
|
|
if (! mShuttingDown) {
|
|
|
|
mShuttingDown = PR_TRUE;
|
1999-11-11 08:51:22 +03:00
|
|
|
|
|
|
|
// Enumerate through each open window and close it
|
2000-02-29 03:20:55 +03:00
|
|
|
if (mWindowMediator) {
|
1999-11-11 08:51:22 +03:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2000-02-29 03:20:55 +03:00
|
|
|
rv = mWindowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
|
1999-11-11 08:51:22 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRBool more;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
rv = windowEnumerator->HasMoreElements(&more);
|
|
|
|
if (NS_FAILED(rv) || !more)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
|
|
|
rv = windowEnumerator->GetNext(getter_AddRefs(isupports));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(isupports);
|
|
|
|
NS_ASSERTION(window != nsnull, "not an nsIDOMWindow");
|
|
|
|
if (! window)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
window->Close();
|
1999-08-10 02:28:30 +04:00
|
|
|
}
|
1999-02-17 19:12:10 +03:00
|
|
|
}
|
|
|
|
}
|
1999-11-11 08:51:22 +03:00
|
|
|
|
|
|
|
// Note that we don't allow any premature returns from the above
|
2000-02-22 09:01:57 +03:00
|
|
|
// loop: no matter what, make sure we send the exit event. If
|
1999-11-11 08:51:22 +03:00
|
|
|
// worst comes to worst, we'll do a leaky shutdown but we WILL
|
2000-02-22 09:01:57 +03:00
|
|
|
// shut down. Well, assuming that all *this* stuff works ;-).
|
|
|
|
nsCOMPtr<nsIEventQueueService> svc = do_GetService(kEventQueueServiceCID, &rv);
|
1999-11-11 08:51:22 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-22 09:01:57 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventQueue> queue;
|
|
|
|
rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
ExitEvent* event = new ExitEvent;
|
|
|
|
if (! event)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PL_InitEvent(NS_REINTERPRET_CAST(PLEvent*, event),
|
|
|
|
nsnull,
|
|
|
|
HandleExitEvent,
|
|
|
|
DestroyExitEvent);
|
|
|
|
|
|
|
|
event->mService = this;
|
|
|
|
NS_ADDREF(event->mService);
|
|
|
|
|
|
|
|
rv = queue->EnterMonitor();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = queue->PostEvent(NS_REINTERPRET_CAST(PLEvent*, event));
|
|
|
|
}
|
|
|
|
(void) queue->ExitMonitor();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(event->mService);
|
|
|
|
delete event;
|
|
|
|
}
|
1999-11-11 08:51:22 +03:00
|
|
|
}
|
|
|
|
|
2000-02-22 09:01:57 +03:00
|
|
|
return rv;
|
1999-11-11 08:51:22 +03:00
|
|
|
}
|
|
|
|
|
2000-02-22 09:01:57 +03:00
|
|
|
void*
|
|
|
|
nsAppShellService::HandleExitEvent(PLEvent* aEvent)
|
1999-11-11 08:51:22 +03:00
|
|
|
{
|
2000-02-22 09:01:57 +03:00
|
|
|
ExitEvent* event = NS_REINTERPRET_CAST(ExitEvent*, aEvent);
|
1999-11-11 08:51:22 +03:00
|
|
|
|
|
|
|
// Tell the appshell to exit
|
2000-02-22 09:01:57 +03:00
|
|
|
event->mService->mAppShell->Exit();
|
1999-11-11 08:51:22 +03:00
|
|
|
|
2000-02-22 09:01:57 +03:00
|
|
|
// We're done "shutting down".
|
|
|
|
event->mService->mShuttingDown = PR_FALSE;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShellService::DestroyExitEvent(PLEvent* aEvent)
|
|
|
|
{
|
|
|
|
ExitEvent* event = NS_REINTERPRET_CAST(ExitEvent*, aEvent);
|
|
|
|
NS_RELEASE(event->mService);
|
|
|
|
delete event;
|
1999-09-17 03:42:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Shutdown(void)
|
|
|
|
{
|
|
|
|
// Shutdown all components.
|
|
|
|
EnumerateComponents(&nsAppShellService::ShutdownComponent);
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new top level window and display the given URL within it...
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent,
|
1999-07-27 10:34:25 +04:00
|
|
|
nsIURI *aUrl,
|
1999-08-17 02:23:19 +04:00
|
|
|
PRBool aShowWindow, PRBool aLoadDefaultPage,
|
1999-07-27 10:34:25 +04:00
|
|
|
PRUint32 aChromeMask,
|
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
|
2000-02-29 03:20:55 +03:00
|
|
|
nsIXULWindow **aResult)
|
1999-07-27 10:34:25 +04:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-07-20 18:40:55 +04:00
|
|
|
|
1999-08-17 02:23:19 +04:00
|
|
|
rv = JustCreateTopWindow(aParent, aUrl, aShowWindow, aLoadDefaultPage,
|
|
|
|
aChromeMask, aCallbacks,
|
|
|
|
aInitialWidth, aInitialHeight,
|
1999-07-27 10:34:25 +04:00
|
|
|
aResult);
|
1999-07-20 18:40:55 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
// the addref resulting from this is the owning addref for this window
|
|
|
|
RegisterTopLevelWindow(*aResult);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just do the window-making part of CreateTopLevelWindow
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,
|
1999-07-27 10:34:25 +04:00
|
|
|
nsIURI *aUrl,
|
1999-08-17 02:23:19 +04:00
|
|
|
PRBool aShowWindow, PRBool aLoadDefaultPage,
|
1999-07-27 10:34:25 +04:00
|
|
|
PRUint32 aChromeMask,
|
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
|
2000-02-29 03:20:55 +03:00
|
|
|
nsIXULWindow **aResult)
|
1999-07-20 18:40:55 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1998-12-03 04:35:53 +03:00
|
|
|
nsWebShellWindow* window;
|
1999-07-20 18:40:55 +04:00
|
|
|
PRBool intrinsicallySized;
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-06-24 07:29:22 +04:00
|
|
|
*aResult = nsnull;
|
1999-07-20 18:40:55 +04:00
|
|
|
intrinsicallySized = PR_FALSE;
|
1998-12-03 04:35:53 +03:00
|
|
|
window = new nsWebShellWindow();
|
2000-02-08 23:19:00 +03:00
|
|
|
// Bump count to one so it doesn't die on us while doing init.
|
|
|
|
nsCOMPtr<nsIXULWindow> tempRef(window);
|
1999-07-27 10:34:25 +04:00
|
|
|
if (!window)
|
1998-12-03 04:35:53 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
1999-07-27 10:34:25 +04:00
|
|
|
else {
|
1999-07-01 06:50:53 +04:00
|
|
|
nsWidgetInitData widgetInitData;
|
1999-07-27 10:34:25 +04:00
|
|
|
|
|
|
|
widgetInitData.mWindowType = aChromeMask & NS_CHROME_OPEN_AS_DIALOG ?
|
|
|
|
eWindowType_dialog : eWindowType_toplevel;
|
|
|
|
|
1999-08-07 06:51:03 +04:00
|
|
|
// note default chrome overrides other OS chrome settings, but
|
|
|
|
// not internal chrome
|
|
|
|
if (aChromeMask & NS_CHROME_DEFAULT_CHROME)
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_default;
|
|
|
|
else if ((aChromeMask & NS_CHROME_ALL_CHROME) == NS_CHROME_ALL_CHROME)
|
1999-07-27 10:34:25 +04:00
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_all;
|
1999-07-28 02:42:34 +04:00
|
|
|
else {
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_none; // assumes none == 0x00
|
|
|
|
if (aChromeMask & NS_CHROME_WINDOW_BORDERS_ON)
|
|
|
|
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_border);
|
|
|
|
if (aChromeMask & NS_CHROME_TITLEBAR_ON)
|
|
|
|
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_title);
|
|
|
|
if (aChromeMask & NS_CHROME_WINDOW_CLOSE_ON)
|
|
|
|
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_close);
|
|
|
|
if (aChromeMask & NS_CHROME_WINDOW_RESIZE_ON)
|
|
|
|
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_resizeh | eBorderStyle_minimize | eBorderStyle_maximize | eBorderStyle_menu);
|
|
|
|
}
|
1999-07-01 06:50:53 +04:00
|
|
|
|
1999-07-04 08:09:54 +04:00
|
|
|
if (aInitialWidth == NS_SIZETOCONTENT ||
|
|
|
|
aInitialHeight == NS_SIZETOCONTENT) {
|
1999-07-05 20:53:43 +04:00
|
|
|
aInitialWidth = 1;
|
|
|
|
aInitialHeight = 1;
|
1999-07-20 18:40:55 +04:00
|
|
|
intrinsicallySized = PR_TRUE;
|
1999-07-04 08:09:54 +04:00
|
|
|
window->SetIntrinsicallySized(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1999-08-13 02:08:17 +04:00
|
|
|
rv = window->Initialize(aParent, mAppShell, aUrl,
|
1999-10-05 08:04:16 +04:00
|
|
|
aShowWindow, aLoadDefaultPage, aCallbacks,
|
1999-07-01 06:50:53 +04:00
|
|
|
aInitialWidth, aInitialHeight, widgetInitData);
|
1999-07-04 08:09:54 +04:00
|
|
|
|
1999-07-20 18:40:55 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
1999-06-20 01:48:53 +04:00
|
|
|
// this does the AddRef of the return value
|
2000-02-29 03:20:55 +03:00
|
|
|
rv = CallQueryInterface(NS_STATIC_CAST(nsIWebShellWindow*, window), aResult);
|
1999-12-06 04:42:11 +03:00
|
|
|
#if 0
|
|
|
|
// If intrinsically sized, don't show until we have the size figured out
|
|
|
|
// (6 Dec 99: this is causing new windows opened from anchor links to
|
|
|
|
// be visible too early. All windows should (and appear to in testing)
|
|
|
|
// become visible in nsWebShellWindow::OnEndDocumentLoad. Timidly
|
|
|
|
// commenting out for now.)
|
1999-07-27 10:34:25 +04:00
|
|
|
if (aShowWindow && !intrinsicallySized)
|
1999-07-20 18:40:55 +04:00
|
|
|
window->Show(PR_TRUE);
|
1999-12-06 04:42:11 +03:00
|
|
|
#endif
|
1999-07-20 18:40:55 +04:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::CloseTopLevelWindow(nsIXULWindow* aWindow)
|
1999-02-15 08:38:15 +03:00
|
|
|
{
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIWebShellWindow> webShellWin(do_QueryInterface(aWindow));
|
|
|
|
NS_ENSURE_TRUE(webShellWin, NS_ERROR_FAILURE);
|
|
|
|
return webShellWin->Close();
|
1999-02-15 08:38:15 +03:00
|
|
|
}
|
|
|
|
|
1999-07-20 18:40:55 +04:00
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::GetHiddenWindow(nsIXULWindow **aWindow)
|
1999-07-20 18:40:55 +04:00
|
|
|
{
|
2000-02-29 03:20:55 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
*aWindow = mHiddenWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return *aWindow ? NS_OK : NS_ERROR_FAILURE;
|
1999-07-20 18:40:55 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 18:04:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetHiddenWindowAndJSContext(nsIDOMWindow **aWindow,
|
|
|
|
JSContext **aJSContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if ( aWindow && aJSContext ) {
|
|
|
|
*aWindow = nsnull;
|
|
|
|
*aJSContext = nsnull;
|
|
|
|
|
|
|
|
if ( mHiddenWindow ) {
|
|
|
|
// Convert hidden window to nsIDOMWindow and extract its JSContext.
|
|
|
|
do {
|
2000-02-29 03:20:55 +03:00
|
|
|
// 1. Get doc for hidden window.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell));
|
1999-10-08 18:04:17 +04:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
|
|
|
// 2. Convert that to an nsIDOMWindow.
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> hiddenDOMWindow(do_GetInterface(docShell));
|
|
|
|
if(!hiddenDOMWindow) break;
|
1999-10-08 18:04:17 +04:00
|
|
|
|
|
|
|
// 3. Get script global object for the window.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
sgo = do_QueryInterface( hiddenDOMWindow );
|
|
|
|
if (!sgo) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// 4. Get script context from that.
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext;
|
|
|
|
sgo->GetContext( getter_AddRefs( scriptContext ) );
|
|
|
|
if (!scriptContext) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// 5. Get JSContext from the script context.
|
|
|
|
JSContext *jsContext = (JSContext*)scriptContext->GetNativeContext();
|
|
|
|
if (!jsContext) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// Now, give results to caller.
|
|
|
|
*aWindow = hiddenDOMWindow.get();
|
|
|
|
NS_IF_ADDREF( *aWindow );
|
|
|
|
*aJSContext = jsContext;
|
|
|
|
} while (0);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
/*
|
|
|
|
* Register a new top level window (created elsewhere)
|
|
|
|
*/
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow)
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
2000-02-29 03:20:55 +03:00
|
|
|
mWindowList->AppendElement(aWindow);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
if(mWindowMediator)
|
|
|
|
mWindowMediator->RegisterWindow(aWindow);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-15 08:38:15 +03:00
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
NS_IMETHODIMP
|
2000-02-29 03:20:55 +03:00
|
|
|
nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow)
|
1999-02-15 08:38:15 +03:00
|
|
|
{
|
1999-09-11 10:25:51 +04:00
|
|
|
if (mDeleteCalled) {
|
|
|
|
// return an error code in order to:
|
|
|
|
// - avoid doing anything with other member variables while we are in the destructor
|
|
|
|
// - notify the caller not to release the AppShellService after unregistering the window
|
|
|
|
// (we don't want to be deleted twice consecutively to mHiddenWindow->Close() in our destructor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-05-19 07:03:48 +04:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
if(mWindowMediator)
|
|
|
|
mWindowMediator->UnregisterWindow(aWindow);
|
1999-09-14 08:22:12 +04:00
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
nsresult rv;
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
mWindowList->RemoveElement(aWindow);
|
|
|
|
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
rv = mWindowList->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (0 == cnt)
|
1999-09-17 03:42:49 +04:00
|
|
|
{
|
|
|
|
#if XP_MAC
|
2000-02-29 04:37:49 +03:00
|
|
|
nsCOMPtr<nsIBaseWindow> hiddenWin(do_QueryInterface(mHiddenWindow));
|
|
|
|
if (hiddenWin)
|
1999-10-13 02:20:28 +04:00
|
|
|
{
|
|
|
|
// Given hidden window the focus so it puts up the menu
|
2000-02-29 04:37:49 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
hiddenWin->GetMainWidget(getter_AddRefs(widget));
|
|
|
|
if(widget)
|
1999-10-13 02:20:28 +04:00
|
|
|
widget->SetFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if no hidden window is available (perhaps due to initial
|
|
|
|
// Profile Manager window being cancelled), then just quit
|
|
|
|
Quit();
|
|
|
|
}
|
1999-09-17 03:42:49 +04:00
|
|
|
#else
|
|
|
|
Quit();
|
|
|
|
#endif
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
|
1999-10-22 01:36:25 +04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// nsIObserver interface and friends
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAppShellService::Observe(nsISupports *aSubject,
|
|
|
|
const PRUnichar *aTopic,
|
|
|
|
const PRUnichar *)
|
|
|
|
{
|
|
|
|
nsAutoString topic(aTopic);
|
|
|
|
|
|
|
|
NS_ASSERTION(mAppShell, "appshell service notified before appshell built");
|
|
|
|
if (topic.Equals(gEQActivatedNotification)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eq(do_QueryInterface(aSubject));
|
|
|
|
if (eq)
|
|
|
|
mAppShell->ListenToEventQueue(eq, PR_TRUE);
|
|
|
|
} else if (topic.Equals(gEQDestroyedNotification)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eq(do_QueryInterface(aSubject));
|
|
|
|
if (eq)
|
1999-11-03 05:29:59 +03:00
|
|
|
mAppShell->ListenToEventQueue(eq, PR_FALSE);
|
1999-10-22 01:36:25 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ask nsIObserverService to tell us about nsEventQueue notifications */
|
|
|
|
void nsAppShellService::RegisterObserver(PRBool aRegister)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsISupports *glop;
|
|
|
|
|
|
|
|
nsAutoString topicA(gEQActivatedNotification);
|
|
|
|
nsAutoString topicB(gEQDestroyedNotification);
|
|
|
|
|
|
|
|
// here's a silly dance. seems better to do it than not, though...
|
|
|
|
nsCOMPtr<nsIObserver> weObserve(do_QueryInterface(NS_STATIC_CAST(nsIObserver *, this)));
|
|
|
|
|
1999-11-02 04:10:35 +03:00
|
|
|
NS_ASSERTION(weObserve, "who's been chopping bits off nsAppShellService?");
|
1999-10-22 01:36:25 +04:00
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(NS_OBSERVERSERVICE_PROGID,
|
2000-02-01 17:26:27 +03:00
|
|
|
NS_GET_IID(nsIObserverService), &glop);
|
1999-10-22 01:36:25 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIObserverService *os = NS_STATIC_CAST(nsIObserverService*,glop);
|
1999-11-02 04:10:35 +03:00
|
|
|
if (aRegister) {
|
1999-10-22 01:36:25 +04:00
|
|
|
os->AddObserver(weObserve, topicA.GetUnicode());
|
|
|
|
os->AddObserver(weObserve, topicB.GetUnicode());
|
1999-11-02 04:10:35 +03:00
|
|
|
} else {
|
1999-10-22 01:36:25 +04:00
|
|
|
os->RemoveObserver(weObserve, topicA.GetUnicode());
|
|
|
|
os->RemoveObserver(weObserve, topicB.GetUnicode());
|
|
|
|
}
|
1999-11-02 04:10:35 +03:00
|
|
|
nsServiceManager::ReleaseService(NS_OBSERVERSERVICE_PROGID, glop);
|
1999-10-22 01:36:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-04 17:40:08 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::HideSplashScreen() {
|
|
|
|
// Hide the splash screen (and release it) if there is one.
|
|
|
|
if ( mSplashScreen ) {
|
|
|
|
mSplashScreen->Hide();
|
|
|
|
NS_RELEASE( mSplashScreen );
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|