From 8cc6ac99dcc45b9a013f4f91f6af81a888e220b8 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Mon, 25 Jun 2001 11:27:56 +0000 Subject: [PATCH] Bug 86922 - app hangs after profile migration dialog. r=danm/sr=alecf/a=chofmann --- profile/pref-migrator/src/nsPrefMigration.cpp | 142 ++++++------------ profile/pref-migrator/src/nsPrefMigration.h | 2 +- profile/src/nsProfile.cpp | 120 ++------------- xpfe/appshell/src/nsAppShellService.cpp | 5 +- 4 files changed, 66 insertions(+), 203 deletions(-) diff --git a/profile/pref-migrator/src/nsPrefMigration.cpp b/profile/pref-migrator/src/nsPrefMigration.cpp index 2f02d7a2bd6..12f89f7a714 100644 --- a/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/profile/pref-migrator/src/nsPrefMigration.cpp @@ -57,7 +57,7 @@ #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" -#include "nsIWebBrowserChrome.h" +#include "nsIWindowWatcher.h" #if defined(XP_MAC) && !defined(DEBUG) //lower silly optimization level which takes an age for this file. @@ -309,38 +309,19 @@ NS_IMETHODIMP nsPrefMigration::ProcessPrefs(PRBool showProgressAsModalWindow) { nsresult rv; - nsCOMPtr pmprogressURL; - - NS_WITH_SERVICE(nsIAppShellService, PMProgressAppShell, - kAppShellServiceCID, &rv); + + nsCOMPtr windowWatcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv)); if (NS_FAILED(rv)) return rv; - rv = NS_NewURI(getter_AddRefs(pmprogressURL), PREF_MIGRATION_PROGRESS_URL); + // WindowWatcher can work with or without parent window + rv = windowWatcher->OpenWindow(nsnull, + PREF_MIGRATION_PROGRESS_URL, + "_blank", + "centerscreen,modal,titlebar", + nsnull, + getter_AddRefs(mPMProgressWindow)); if (NS_FAILED(rv)) return rv; - rv = PMProgressAppShell->CreateTopLevelWindow(nsnull, pmprogressURL, - PR_TRUE, PR_TRUE, CHROME_STYLE, - NS_SIZETOCONTENT, NS_SIZETOCONTENT, - getter_AddRefs(mPMProgressWindow)); - if (NS_FAILED(rv)) return rv; - - if (showProgressAsModalWindow) { - nsCOMPtr progressRequestor(do_QueryInterface(mPMProgressWindow)); - nsCOMPtr progressChrome; - - if (progressRequestor) - progressRequestor->GetInterface(NS_GET_IID(nsIWebBrowserChrome), getter_AddRefs(progressChrome)); - - if (progressChrome) - progressChrome->ShowAsModal(); - NS_ASSERTION(progressChrome, "show modal window failed: no available chrome"); - } - else { - // we are automatically migrating the profile, so there is no - // profile manager window to run the dialog as modal in front of. - PMProgressAppShell->Run(); - } - return NS_OK; } @@ -435,19 +416,22 @@ extern "C" void ProfileMigrationController(void *data) NS_IMETHODIMP nsPrefMigration::WindowCloseCallback() { - nsCOMPtr docShell; - nsresult rv = mPMProgressWindow->GetDocShell(getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr treeItem(do_QueryInterface(docShell)); - if (treeItem) { - nsCOMPtr treeOwner; - rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr baseWindow(do_QueryInterface(treeOwner)); - if (baseWindow) (void)baseWindow->Destroy(); - } + nsresult rv; + nsCOMPtr scriptGO(do_QueryInterface(mPMProgressWindow)); + if (!scriptGO) return NS_ERROR_FAILURE; + nsCOMPtr docShell; + rv = scriptGO->GetDocShell(getter_AddRefs(docShell)); + if (!docShell) return NS_ERROR_FAILURE; + nsCOMPtr treeItem(do_QueryInterface(docShell)); + if (!treeItem) return NS_ERROR_FAILURE; + nsCOMPtr treeOwner; + treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); + if (!treeOwner) return NS_ERROR_FAILURE; + nsCOMPtr baseWindow(do_QueryInterface(treeOwner)); + if (baseWindow) + baseWindow->Destroy(); + #ifdef DEBUG printf("end of pref migration\n"); #endif @@ -458,62 +442,30 @@ nsPrefMigration::WindowCloseCallback() NS_IMETHODIMP nsPrefMigration::ShowSpaceDialog(PRInt32 *choice) { - // Get the DocShell - nsCOMPtr docShell; - nsresult rv = mPMProgressWindow->GetDocShell(getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsresult rv; + nsCOMPtr windowWatcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv)); + if (NS_FAILED(rv)) return rv; - // Now convert the DocShell to an nsIDOMWindowInternal - nsCOMPtr PMDOMWindow(do_GetInterface(docShell)); - if (!PMDOMWindow) return NS_ERROR_FAILURE; - - // Get the script global object for the window - nsCOMPtr sgo; - sgo = do_QueryInterface(PMDOMWindow); - if (!sgo) return NS_ERROR_FAILURE; - - // Get the script context from the global context - nsCOMPtr scriptContext; - sgo->GetContext( getter_AddRefs(scriptContext)); - if (!scriptContext) return NS_ERROR_FAILURE; - - // Get the JSContext from the script context - JSContext* jsContext = (JSContext*)scriptContext->GetNativeContext(); - if (!jsContext) return NS_ERROR_FAILURE; - - - //----------------------------------------------------- - // Create the nsIDialogParamBlock to pass the trigger - // list to the dialog - //----------------------------------------------------- - nsCOMPtr ioParamBlock; - rv = nsComponentManager::CreateInstance("@mozilla.org/embedcomp/dialogparam;1", - nsnull, - NS_GET_IID(nsIDialogParamBlock), - getter_AddRefs(ioParamBlock)); - - - if ( NS_SUCCEEDED( rv ) ) - ioParamBlock->SetInt(0,3); //set the Retry, CreateNew and Cancel buttons - - nsCOMPtr ifptr = - do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - ifptr->SetData(ioParamBlock); - ifptr->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr newWindow; - rv = PMDOMWindow->OpenDialog(NS_ConvertASCIItoUCS2(PREF_MIGRATION_NO_SPACE_URL), - NS_LITERAL_STRING("_blank"), - NS_LITERAL_STRING("chrome,modal"), - ifptr, getter_AddRefs(newWindow)); - if (NS_SUCCEEDED(rv)) { - //Now get which button was pressed from the ParamBlock - ioParamBlock->GetInt( 0, choice ); - } + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1", &rv)); + if (NS_FAILED(rv)) return rv; - return rv; + ioParamBlock->SetInt(0,3); //set the Retry, CreateNew and Cancel buttons + + // WindowWatcher can work with or without parent window + nsCOMPtr newWindow; + rv = windowWatcher->OpenWindow(mPMProgressWindow, + PREF_MIGRATION_NO_SPACE_URL, + "_blank", + "dialog,chrome,centerscreen,modal,titlebar", + ioParamBlock, + getter_AddRefs(newWindow)); + if (NS_FAILED(rv)) return rv; + + // Now get which button was pressed from the ParamBlock + if (NS_SUCCEEDED(rv)) + ioParamBlock->GetInt( 0, choice ); + + return NS_OK; } diff --git a/profile/pref-migrator/src/nsPrefMigration.h b/profile/pref-migrator/src/nsPrefMigration.h index dc89ffa13be..8e43663812e 100644 --- a/profile/pref-migrator/src/nsPrefMigration.h +++ b/profile/pref-migrator/src/nsPrefMigration.h @@ -153,7 +153,7 @@ class nsPrefMigration: public nsIPrefMigration nsCOMPtr m_prefs; nsCOMPtr m_prefsFile; nsCOMPtr m_parentWindow; - nsCOMPtr mPMProgressWindow; + nsCOMPtr mPMProgressWindow; }; #endif /* nsPrefMigration_h___ */ diff --git a/profile/src/nsProfile.cpp b/profile/src/nsProfile.cpp index 41132b8e406..f75b67f18d0 100644 --- a/profile/src/nsProfile.cpp +++ b/profile/src/nsProfile.cpp @@ -1919,114 +1919,22 @@ nsProfile::MigrateProfile(const PRUnichar* profileName, PRBool showProgressAsMod nsresult nsProfile::ShowProfileWizard(void) { - nsresult rv = NS_OK; - PRBool hasParentWindow = PR_FALSE; - nsCOMPtr PMDOMWindow; + nsresult rv; + nsCOMPtr windowWatcher(do_GetService(kWindowWatcherContractID, &rv)); + if (NS_FAILED(rv)) return rv; - // Get the window mediator - NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv); - if (NS_SUCCEEDED(rv)) - { - nsCOMPtr windowEnumerator; - - if (NS_SUCCEEDED(windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)))) - { - // Get each dom window - PRBool more; - windowEnumerator->HasMoreElements(&more); - while (more) - { - nsCOMPtr protoWindow; - rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow)); - if (NS_SUCCEEDED(rv) && protoWindow) - { - PMDOMWindow = do_QueryInterface(protoWindow); - if (PMDOMWindow) - { - hasParentWindow = PR_TRUE; - break; - } - } - windowEnumerator->HasMoreElements(&more); - } - } - } - - if (hasParentWindow) - { - // Get the script global object for the window - nsCOMPtr sgo; - sgo = do_QueryInterface(PMDOMWindow); - if (!sgo) return NS_ERROR_FAILURE; - - // Get the script context from the global context - nsCOMPtr scriptContext; - sgo->GetContext( getter_AddRefs(scriptContext)); - if (!scriptContext) return NS_ERROR_FAILURE; - - // Get the JSContext from the script context - JSContext* jsContext = (JSContext*)scriptContext->GetNativeContext(); - if (!jsContext) return NS_ERROR_FAILURE; - - - //----------------------------------------------------- - // Create the nsIDialogParamBlock to pass the trigger - // list to the dialog - //----------------------------------------------------- - nsCOMPtr ioParamBlock; - rv = nsComponentManager::CreateInstance("@mozilla.org/embedcomp/dialogparam;1", - nsnull, - NS_GET_IID(nsIDialogParamBlock), - getter_AddRefs(ioParamBlock)); - - - if ( NS_SUCCEEDED( rv ) ) - ioParamBlock->SetInt(0,4); // standard wizard buttons - - nsCOMPtr ifptr = - do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - ifptr->SetData(ioParamBlock); - ifptr->SetDataIID(&NS_GET_IID(nsIDialogParamBlock)); - - nsCOMPtr newWindow; - rv = PMDOMWindow->OpenDialog(NS_ConvertUTF8toUCS2(PROFILE_WIZARD_URL), - NS_LITERAL_STRING("_blank"), - NS_LITERAL_STRING("chrome,modal"), - ifptr, getter_AddRefs(newWindow)); - if (NS_FAILED(rv)) { - return rv; - } - } - else - { - // No parent window is available. - // So, Create top level window with create profile wizard - NS_WITH_SERVICE(nsIAppShellService, wizAppShell, - kAppShellServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr profURI; - rv = NS_NewURI(getter_AddRefs(profURI), NS_LITERAL_CSTRING(PROFILE_WIZARD_URL).get()); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr newWindow; - rv = wizAppShell->CreateTopLevelWindow(nsnull, profURI, - PR_TRUE, PR_TRUE, CHROME_STYLE, - NS_SIZETOCONTENT, // width - NS_SIZETOCONTENT, // height - getter_AddRefs(newWindow)); - - if (NS_FAILED(rv)) return rv; - - /* - * Bring up the wizard... - */ - rv = wizAppShell->Run(); - } + nsCOMPtr ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1", &rv)); + if (NS_FAILED(rv)) return rv; + ioParamBlock->SetInt(0,4); // standard wizard buttons + + nsCOMPtr newWindow; + rv = windowWatcher->OpenWindow(nsnull, + PROFILE_WIZARD_URL, + "_blank", + kDefaultOpenWindowParams, + ioParamBlock, + getter_AddRefs(newWindow)); return rv; - } NS_IMETHODIMP nsProfile::ProfileExists(const PRUnichar *profileName, PRBool *exists) diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 3bb69def120..b8f83801734 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -802,6 +802,9 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow) if (NS_FAILED(rv)) return rv; if (0 == cnt) { + if (!mQuitOnLastWindowClosing) + return NS_OK; + #if XP_MAC // if no hidden window is available (perhaps due to initial // Profile Manager window being cancelled), then just quit. We don't have @@ -815,7 +818,7 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow) PRBool serverMode = PR_FALSE; if (mNativeAppSupport) mNativeAppSupport->GetIsServerMode(&serverMode); - if (!mQuitOnLastWindowClosing || serverMode) + if (serverMode) return NS_OK; Quit();