From b539354e4b6ffdd063e55fa822d05c28c07bd68a Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Wed, 20 Jun 2001 06:49:22 +0000 Subject: [PATCH] Bug 86021 - enable multiple profiles in -turbo mode. r=racham/sr=alecf/a=chofmann git-svn-id: svn://10.0.0.236/trunk@97581 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libpref/src/nsPrefService.cpp | 3 +- .../resources/content/createProfileWizard.js | 17 ++------- .../resources/content/profileSelection.js | 13 +------ mozilla/profile/src/nsProfile.cpp | 36 +++++++++++-------- .../appshell/public/nsIAppShellService.idl | 8 +++++ .../appshell/public/nsINativeAppSupport.idl | 7 ++++ .../xpfe/appshell/src/nsAppShellService.cpp | 33 +++++++++++------ mozilla/xpfe/appshell/src/nsAppShellService.h | 1 + mozilla/xpfe/bootstrap/nsAppRunner.cpp | 23 +++++++++--- .../xpfe/bootstrap/nsNativeAppSupportBase.cpp | 16 ++++++++- .../xpfe/bootstrap/nsNativeAppSupportBase.h | 1 + .../startup/public/nsINativeAppSupport.idl | 7 ++++ 12 files changed, 107 insertions(+), 58 deletions(-) diff --git a/mozilla/modules/libpref/src/nsPrefService.cpp b/mozilla/modules/libpref/src/nsPrefService.cpp index 0e6a128e42d..f0d520dab9f 100644 --- a/mozilla/modules/libpref/src/nsPrefService.cpp +++ b/mozilla/modules/libpref/src/nsPrefService.cpp @@ -251,7 +251,8 @@ NS_IMETHODIMP nsPrefService::ResetUserPrefs() NS_IMETHODIMP nsPrefService::SavePrefFile(nsIFile *aFile) { if (nsnull == aFile) { - return savePrefFile(mCurrentFile); + // It's possible that we never got a prefs file. + return mCurrentFile ? savePrefFile(mCurrentFile) : NS_OK; } else { return savePrefFile(aFile); } diff --git a/mozilla/profile/resources/content/createProfileWizard.js b/mozilla/profile/resources/content/createProfileWizard.js index 734ef5ce356..0c675dfeeab 100644 --- a/mozilla/profile/resources/content/createProfileWizard.js +++ b/mozilla/profile/resources/content/createProfileWizard.js @@ -76,7 +76,7 @@ function onCancel() catch (ex) { dump("failed to forget current profile.\n"); } - ExitApp(); + window.close(); } } @@ -126,12 +126,11 @@ function onFinish() if( window.opener ) { window.opener.CreateProfile(profName, profDir); - window.close(); } else { profile.startApprunner(profName); - ExitApp(); } + window.close(); } else return; @@ -201,15 +200,3 @@ function processCreateProfileData( aProfName, aProfDir, langcode, regioncode) } } -/** void ExitApp( void ) ; - * - purpose: quits the application properly and finally, stops event loop - * - in: nothing - * - out: nothing - **/ -function ExitApp() -{ - // Need to call this to stop the event loop - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService); - appShell.Quit(); -} diff --git a/mozilla/profile/resources/content/profileSelection.js b/mozilla/profile/resources/content/profileSelection.js index 5ea44cab640..6651bd3af49 100644 --- a/mozilla/profile/resources/content/profileSelection.js +++ b/mozilla/profile/resources/content/profileSelection.js @@ -220,7 +220,6 @@ function onStart() } profile.startApprunner(profilename); - ExitApp(); } catch (ex) { //var stringA = gProfileManagerBundle.getString(failProfileStartA); @@ -236,21 +235,11 @@ function onExit() { try { profile.forgetCurrentProfile(); + window.close(); } catch (ex) { dump("Failed to forget current profile.\n"); } - ExitApp(); -} - -// function : ::ExitApp(); -// purpose : halts startup process forcefully -function ExitApp() -{ - // Need to call this to stop the event loop - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService); - appShell.Quit(); } function foo() diff --git a/mozilla/profile/src/nsProfile.cpp b/mozilla/profile/src/nsProfile.cpp index 651febe0f9a..41132b8e406 100644 --- a/mozilla/profile/src/nsProfile.cpp +++ b/mozilla/profile/src/nsProfile.cpp @@ -75,6 +75,7 @@ #include "nsIDialogParamBlock.h" #include "nsIDOMWindowInternal.h" #include "nsIWindowMediator.h" +#include "nsIWindowWatcher.h" #if defined (XP_UNIX) #elif defined (XP_MAC) @@ -112,6 +113,11 @@ #define CHROME_STYLE nsIWebBrowserChrome::CHROME_ALL | nsIWebBrowserChrome::CHROME_CENTER_SCREEN #endif +const char* kWindowWatcherContractID = "@mozilla.org/embedcomp/window-watcher;1"; +const char* kDialogParamBlockContractID = "@mozilla.org/embedcomp/dialogparam;1"; + +const char* kDefaultOpenWindowParams = "centerscreen,chrome,modal,titlebar"; + // we want everyone to have the debugging info to the console for now // to help track down profile manager problems // when we ship, we'll turn this off @@ -468,24 +474,24 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr, PRBool canInteract) if (profileURLStr.Length() != 0) { if (!canInteract) return NS_ERROR_PROFILE_REQUIRES_INTERACTION; - - NS_WITH_SERVICE(nsIAppShellService, profAppShell, kAppShellServiceCID, &rv); + + nsCOMPtr windowWatcher(do_GetService(kWindowWatcherContractID, &rv)); if (NS_FAILED(rv)) return rv; - - rv = NS_NewURI(getter_AddRefs(profileURL), (const char *)profileURLStr); + + // We need to send a param to OpenWindow if the window is to be considered + // a dialog. It needs to be for script security reasons. This param block + // will be made use of soon. See bug 66833. + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1", &rv)); if (NS_FAILED(rv)) return rv; - - nsCOMPtr profWindow; - rv = profAppShell->CreateTopLevelWindow(nsnull, profileURL, - PR_TRUE, PR_TRUE, CHROME_STYLE, - NS_SIZETOCONTENT, // width - NS_SIZETOCONTENT, // height - getter_AddRefs(profWindow)); - + + nsCOMPtr newWindow; + rv = windowWatcher->OpenWindow(nsnull, + profileURLStr.get(), + "_blank", + kDefaultOpenWindowParams, + ioParamBlock, + getter_AddRefs(newWindow)); if (NS_FAILED(rv)) return rv; - - // Start an event loop for the modal dialog - rv = profAppShell->Run(); } PRBool confirmAutomigration = PR_FALSE; diff --git a/mozilla/xpfe/appshell/public/nsIAppShellService.idl b/mozilla/xpfe/appshell/public/nsIAppShellService.idl index e15a1b878e2..9a5d00785c1 100644 --- a/mozilla/xpfe/appshell/public/nsIAppShellService.idl +++ b/mozilla/xpfe/appshell/public/nsIAppShellService.idl @@ -171,4 +171,12 @@ interface nsIAppShellService : nsISupports * only once per application session. */ void HideSplashScreen(); + + /** + * We may need to show a XUL dialog before there are any other windows. + * In this case we don't nescesarily want to quit when it is closed. + * Use with extreme caution. + */ + + attribute boolean quitOnLastWindowClosing; }; diff --git a/mozilla/xpfe/appshell/public/nsINativeAppSupport.idl b/mozilla/xpfe/appshell/public/nsINativeAppSupport.idl index 48915973806..0a919fe0307 100644 --- a/mozilla/xpfe/appshell/public/nsINativeAppSupport.idl +++ b/mozilla/xpfe/appshell/public/nsINativeAppSupport.idl @@ -143,6 +143,12 @@ * mode is currently Win32-only (and may really only make * sense there) and is intended to be initiated from the * Windows startup folder at system initialization. + * + * needsProfileUI - Boolean attribute used when running in "server mode." + * If the "server mode" caused profile dialogs to be + * suppressed, this should be set to true. When the server + * starts a real session, it will call on the profile mgr + * to do what it needed to do when this attribute is true. */ interface nsIDOMWindow; @@ -161,4 +167,5 @@ interface nsINativeAppSupport : nsISupports { // Server mode. attribute boolean isServerMode; void startServerMode(); + attribute boolean needsProfileUI; }; diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.cpp b/mozilla/xpfe/appshell/src/nsAppShellService.cpp index 40f80f74fac..3bb69def120 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellService.cpp @@ -80,7 +80,8 @@ nsAppShellService::nsAppShellService() : mDeleteCalled( PR_FALSE ), mSplashScreen( nsnull ), mNativeAppSupport( nsnull ), - mShuttingDown( PR_FALSE ) + mShuttingDown( PR_FALSE ), + mQuitOnLastWindowClosing( PR_TRUE ) { NS_INIT_REFCNT(); } @@ -810,21 +811,33 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow) if (!hiddenWin) Quit(); #else - // Check to see if we're in server mode, first. - if ( mNativeAppSupport ) { - PRBool serverMode = PR_FALSE; - mNativeAppSupport->GetIsServerMode( &serverMode ); - if ( serverMode ) { - // Then don't quit. - return NS_OK; - } - } + // Check to see if we should quit in this case. + PRBool serverMode = PR_FALSE; + if (mNativeAppSupport) + mNativeAppSupport->GetIsServerMode(&serverMode); + if (!mQuitOnLastWindowClosing || serverMode) + return NS_OK; + Quit(); #endif } return rv; } +NS_IMETHODIMP +nsAppShellService::GetQuitOnLastWindowClosing(PRBool *aQuitOnLastWindowClosing) +{ + NS_ENSURE_ARG_POINTER(aQuitOnLastWindowClosing); + *aQuitOnLastWindowClosing = mQuitOnLastWindowClosing; + return NS_OK; +} + +NS_IMETHODIMP +nsAppShellService::SetQuitOnLastWindowClosing(PRBool aQuitOnLastWindowClosing) +{ + mQuitOnLastWindowClosing = aQuitOnLastWindowClosing; + return NS_OK; +} //------------------------------------------------------------------------- diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.h b/mozilla/xpfe/appshell/src/nsAppShellService.h index f293b682c76..d9def63a62e 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.h +++ b/mozilla/xpfe/appshell/src/nsAppShellService.h @@ -73,6 +73,7 @@ protected: // Set when the appshell service is going away. PRBool mShuttingDown; + PRBool mQuitOnLastWindowClosing; // A "last event" that is used to flush the appshell's event queue. struct ExitEvent { diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 3cc8188ad25..6e6105cebe2 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -832,10 +832,20 @@ static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs) NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager"); if (NS_FAILED(rv)) return rv; + nsCOMPtr nativeApp; + PRBool serverMode = PR_FALSE; + GetNativeAppSupport(getter_AddRefs(nativeApp)); + if (nativeApp) + nativeApp->GetIsServerMode(&serverMode); + // If we are in server mode, profile mgr cannot show UI - rv = profileMgr->StartupWithArgs(cmdLineArgs, !IsAppInServerMode()); + rv = profileMgr->StartupWithArgs(cmdLineArgs, !serverMode); NS_ASSERTION(NS_SUCCEEDED(rv), "StartupWithArgs failed\n"); - if (NS_FAILED(rv)) return rv; + if (serverMode && rv == NS_ERROR_PROFILE_REQUIRES_INTERACTION) { + nativeApp->SetNeedsProfileUI(PR_TRUE); + rv = NS_OK; + } + else if (NS_FAILED(rv)) return rv; // if we get here, and we don't have a current profile, return a failure so we will exit // this can happen, if the user hits Cancel or Exit in the profile manager dialogs @@ -1095,11 +1105,14 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize appshell"); if (NS_FAILED(rv)) return rv; - + rv = InitializeWindowCreator(); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize window creator"); if (NS_FAILED(rv)) return rv; + // So we can open and close windows during startup + appShell->SetQuitOnLastWindowClosing(PR_FALSE); + // Initialize Profile Service here. rv = InitializeProfileService(cmdLineArgs); if (NS_FAILED(rv)) return rv; @@ -1134,7 +1147,9 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) nsCOMPtr walletService(do_GetService(NS_WALLETSERVICE_CONTRACTID, &rv)); InitCachePrefs(); - + + // From this point on, should be true + appShell->SetQuitOnLastWindowClosing(PR_TRUE); // Start main event loop rv = appShell->Run(); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell"); diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.cpp index a755b6ea48e..f338cf751e1 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.cpp @@ -25,7 +25,8 @@ nsNativeAppSupportBase::nsNativeAppSupportBase() : mRefCnt( 0 ), mSplash( 0 ), - mServerMode( PR_FALSE ) { + mServerMode( PR_FALSE ), + mNeedsProfileUI( PR_FALSE ) { } nsNativeAppSupportBase::~nsNativeAppSupportBase() { @@ -92,6 +93,19 @@ nsNativeAppSupportBase::GetIsServerMode(PRBool *aIsServerMode) { return NS_OK; } +NS_IMETHODIMP +nsNativeAppSupportBase::GetNeedsProfileUI(PRBool *aNeedsProfileUI) { + NS_ENSURE_ARG_POINTER(aNeedsProfileUI); + *aNeedsProfileUI = mNeedsProfileUI; + return NS_OK; +} + +NS_IMETHODIMP +nsNativeAppSupportBase::SetNeedsProfileUI(PRBool aNeedsProfileUI) { + mNeedsProfileUI = aNeedsProfileUI; + return NS_OK; +} + NS_IMETHODIMP nsNativeAppSupportBase::StartServerMode() { return NS_OK; diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.h b/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.h index d5e5c84c494..bd05c7ac7fd 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.h +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportBase.h @@ -53,5 +53,6 @@ public: nsrefcnt mRefCnt; nsCOMPtr mSplash; PRBool mServerMode; + PRBool mNeedsProfileUI; }; // class nsSplashScreenWin diff --git a/mozilla/xpfe/components/startup/public/nsINativeAppSupport.idl b/mozilla/xpfe/components/startup/public/nsINativeAppSupport.idl index 48915973806..0a919fe0307 100644 --- a/mozilla/xpfe/components/startup/public/nsINativeAppSupport.idl +++ b/mozilla/xpfe/components/startup/public/nsINativeAppSupport.idl @@ -143,6 +143,12 @@ * mode is currently Win32-only (and may really only make * sense there) and is intended to be initiated from the * Windows startup folder at system initialization. + * + * needsProfileUI - Boolean attribute used when running in "server mode." + * If the "server mode" caused profile dialogs to be + * suppressed, this should be set to true. When the server + * starts a real session, it will call on the profile mgr + * to do what it needed to do when this attribute is true. */ interface nsIDOMWindow; @@ -161,4 +167,5 @@ interface nsINativeAppSupport : nsISupports { // Server mode. attribute boolean isServerMode; void startServerMode(); + attribute boolean needsProfileUI; };