diff --git a/mailnews/compose/src/nsComposeAppCore.cpp b/mailnews/compose/src/nsComposeAppCore.cpp index 401ed0885aa8..5ce754802692 100644 --- a/mailnews/compose/src/nsComposeAppCore.cpp +++ b/mailnews/compose/src/nsComposeAppCore.cpp @@ -740,20 +740,22 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl, { rv = pNetService->CreateURL(&url, aUrl); if (NS_FAILED(rv)) - goto done; + goto done; // goto in C++ is evil! } else - goto done; + goto done; // goto in C++ is evil! + nsCOMPtr newWindow; appShell->CreateTopLevelWindow(nsnull, // parent url, PR_TRUE, - mWebShellWindow, // result widget + *getter_AddRefs(newWindow), // result widget nsnull, // observer this, // callbacks 615, // width 650); // height + mWebShellWindow = newWindow; // Get the default charset from pref, use this as a mail charset. default_mail_charset = nsMsgI18NGetDefaultMailCharset(); if (NULL != default_mail_charset) { diff --git a/xpfe/AppCores/src/nsDOMPropsCore.cpp b/xpfe/AppCores/src/nsDOMPropsCore.cpp index 0f3047dc2295..66e0954cc5f0 100644 --- a/xpfe/AppCores/src/nsDOMPropsCore.cpp +++ b/xpfe/AppCores/src/nsDOMPropsCore.cpp @@ -463,13 +463,13 @@ nsDOMPropsCore::ShowProperties(const nsString& aUrl, nsIDOMWindow* aParent, nsID if (NS_FAILED(rv)) return rv; - nsIWebShellWindow *newWindow; nsPropertiesDialog *dialog = new nsPropertiesDialog(aNode); nsCOMPtr parent = DOMWindowToWebShellWindow(aParent); - rv = appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, newWindow, + nsCOMPtr newWindow; + rv = appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, *getter_AddRefs(newWindow), nsnull, dialog, 450, 240); nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); diff --git a/xpfe/appshell/src/nsCommandLineServiceMac.cpp b/xpfe/appshell/src/nsCommandLineServiceMac.cpp index 72527415ffa7..bfcb095b6b39 100644 --- a/xpfe/appshell/src/nsCommandLineServiceMac.cpp +++ b/xpfe/appshell/src/nsCommandLineServiceMac.cpp @@ -536,7 +536,7 @@ OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFil // Another way, but this way loads the URL as the "chrome" - no toolbar, etc. // Personally, I like this better, but it's not "right" :-) - nsIWebShellWindow* aWindow = FindWebShellWindow(nsnull); + nsCOMPtr aWindow = getter_AddRefs(FindWebShellWindow(nsnull)); if (!aWindow) return errAEEventNotHandled; @@ -760,7 +760,7 @@ Clean: // evaluate the javascript till after javascript is initialized. // nsCOMPtr cb( // nsDontQueryInterface(new nsJavascriptCallbacks(scriptText))); - nsIWebShellWindow* aWindow = FindWebShellWindow(nsnull); + nsCOMPtr aWindow = getter_AddRefs(FindWebShellWindow(nsnull)); if (!aWindow) return errAEEventNotHandled; @@ -971,6 +971,7 @@ OSErr nsAppleEventHandler::SetAEProperty(DescType inProperty, } //---------------------------------------------------------------------------------------- +// The return value has been AddRefed. Callers should release it. nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) //---------------------------------------------------------------------------------------- { @@ -980,7 +981,6 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) if (NS_FAILED(rv)) return nsnull; - nsIWebShellWindow* aWindow; const PRInt32 windowWidth = 615; const PRInt32 windowHeight = 650; nsCOMPtr urlObj; @@ -1000,6 +1000,8 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) #endif // NECKO if (NS_FAILED(rv)) return nsnull; + + nsIWebShellWindow *aWindow = nsnull; // we will return the window AddRefed rv = appShellService->CreateTopLevelWindow( nsnull, urlObj, // nsIURL* of chrome diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index 5d2f4bfda087..2dc7b4c87af8 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -26,6 +26,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #endif // NECKO #include "nsIWidget.h" +#include "nsIWebShellWindow.h" #include "nsIPref.h" #include "plevent.h" #include "prmem.h" @@ -258,7 +259,7 @@ int main(int argc, char* argv[]) if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } profileService->Startup(nsnull); @@ -276,14 +277,14 @@ int main(int argc, char* argv[]) (nsISupports **)&cmdLineArgs); if (NS_FAILED(rv)) { fprintf(stderr, "Could not obtain CmdLine processing service\n"); - goto done; + goto done; // don't use goto in C++! } // Initialize the cmd line service rv = cmdLineArgs->Initialize(argc, argv); if (rv == NS_ERROR_INVALID_ARG) { PrintUsage(); - goto done; + goto done; // don't use goto in C++! } #if 0 @@ -291,7 +292,7 @@ int main(int argc, char* argv[]) rv = cmdLineArgs->GetURLToLoad(&urlstr); if (rv == NS_ERROR_INVALID_ARG) { PrintUsage(); - goto done; + goto done; // don't use goto in C++! } #endif /* 0 */ @@ -445,7 +446,7 @@ int main(int argc, char* argv[]) // Get the value of -width option rv = cmdLineArgs->GetCmdLineValue("-width", &width); if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } if (width) { PR_sscanf(width, "%d", &widthVal); @@ -457,7 +458,7 @@ int main(int argc, char* argv[]) // Get the value of -height option rv = cmdLineArgs->GetCmdLineValue("-height", &height); if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } if (height) { PR_sscanf(height, "%d", &heightVal); @@ -473,7 +474,7 @@ int main(int argc, char* argv[]) nsIPref::GetIID(), (nsISupports **)&prefs); if (NS_FAILED(rv)) - goto done; + goto done; // don't use goto in C++! /* * Create the Application Shell instance... @@ -482,7 +483,7 @@ int main(int argc, char* argv[]) kIAppShellServiceIID, (nsISupports**)&appShell); if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } /* @@ -490,7 +491,7 @@ int main(int argc, char* argv[]) */ rv = appShell->Initialize( cmdLineArgs ); if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } /* @@ -501,7 +502,6 @@ int main(int argc, char* argv[]) * deal with GUI initialization... */ ///write me... - nsIWebShellWindow* newWindow; #ifndef NECKO rv = NS_NewURL(&url, urlstr); @@ -519,7 +519,7 @@ int main(int argc, char* argv[]) #endif // NECKO if (NS_FAILED(rv)) { - goto done; + goto done; // don't use goto in C++! } /* ********************************************************************* */ @@ -595,7 +595,6 @@ int main(int argc, char* argv[]) PRInt32 profWinWidth = 615; PRInt32 profWinHeight = 500; - nsIWebShellWindow* profWindow; nsIAppShellService* profAppShell; /* @@ -628,7 +627,8 @@ int main(int argc, char* argv[]) goto done; } - rv = profAppShell->CreateTopLevelWindow(nsnull, profURL, PR_TRUE, profWindow, + nsCOMPtr profWindow; + rv = profAppShell->CreateTopLevelWindow(nsnull, profURL, PR_TRUE, *getter_AddRefs(profWindow), nsnull, nsnull, profWinWidth, profWinHeight); NS_RELEASE(profURL); @@ -656,7 +656,8 @@ int main(int argc, char* argv[]) goto done; if ( !useArgs ) { - rv = appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, newWindow, + nsCOMPtr newWindow; + rv = appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, *getter_AddRefs(newWindow), nsnull, nsnull, widthVal, heightVal); } else { nsIDOMToolkitCore* toolkit = nsnull; @@ -664,7 +665,6 @@ int main(int argc, char* argv[]) nsIDOMToolkitCore::GetIID(), (nsISupports**)&toolkit); if (NS_SUCCEEDED(rv)) { - nsIWebShellWindow* newWindow = nsnull; toolkit->ShowWindowWithArgs( urlstr, nsnull, withArgs ); diff --git a/xpfe/components/find/src/nsFindComponent.cpp b/xpfe/components/find/src/nsFindComponent.cpp index 69ef03da164c..7bf7f72266cc 100644 --- a/xpfe/components/find/src/nsFindComponent.cpp +++ b/xpfe/components/find/src/nsFindComponent.cpp @@ -631,7 +631,6 @@ nsFindComponent::Find(nsISupports *aContext, PRBool *aDidFind) Context *context = (Context*)aContext; // Open Find dialog and prompt for search parameters. - nsIWebShellWindow *newWindow; // Make url for dialog xul. nsIURL *url; @@ -657,10 +656,11 @@ nsFindComponent::Find(nsISupports *aContext, PRBool *aDidFind) // Create callbacks object for the find dialog. nsFindDialog *dialog = new nsFindDialog( this, context ); + nsCOMPtr newWindow; rv = mAppShell->CreateTopLevelWindow( nsnull, url, PR_TRUE, - newWindow, + *getter_AddRefs(newWindow), nsnull, dialog, 0, diff --git a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp index 72527415ffa7..bfcb095b6b39 100644 --- a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp +++ b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp @@ -536,7 +536,7 @@ OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFil // Another way, but this way loads the URL as the "chrome" - no toolbar, etc. // Personally, I like this better, but it's not "right" :-) - nsIWebShellWindow* aWindow = FindWebShellWindow(nsnull); + nsCOMPtr aWindow = getter_AddRefs(FindWebShellWindow(nsnull)); if (!aWindow) return errAEEventNotHandled; @@ -760,7 +760,7 @@ Clean: // evaluate the javascript till after javascript is initialized. // nsCOMPtr cb( // nsDontQueryInterface(new nsJavascriptCallbacks(scriptText))); - nsIWebShellWindow* aWindow = FindWebShellWindow(nsnull); + nsCOMPtr aWindow = getter_AddRefs(FindWebShellWindow(nsnull)); if (!aWindow) return errAEEventNotHandled; @@ -971,6 +971,7 @@ OSErr nsAppleEventHandler::SetAEProperty(DescType inProperty, } //---------------------------------------------------------------------------------------- +// The return value has been AddRefed. Callers should release it. nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) //---------------------------------------------------------------------------------------- { @@ -980,7 +981,6 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) if (NS_FAILED(rv)) return nsnull; - nsIWebShellWindow* aWindow; const PRInt32 windowWidth = 615; const PRInt32 windowHeight = 650; nsCOMPtr urlObj; @@ -1000,6 +1000,8 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) #endif // NECKO if (NS_FAILED(rv)) return nsnull; + + nsIWebShellWindow *aWindow = nsnull; // we will return the window AddRefed rv = appShellService->CreateTopLevelWindow( nsnull, urlObj, // nsIURL* of chrome diff --git a/xpfe/components/xfer/src/nsDownloadProgressDialog.cpp b/xpfe/components/xfer/src/nsDownloadProgressDialog.cpp index 7f7cd7af1047..dcadf35820fa 100644 --- a/xpfe/components/xfer/src/nsDownloadProgressDialog.cpp +++ b/xpfe/components/xfer/src/nsDownloadProgressDialog.cpp @@ -163,18 +163,17 @@ nsDownloadProgressDialog::Show() { if ( NS_SUCCEEDED(rv) ) { // Create "save to disk" nsIXULCallbacks... - nsIWebShellWindow *newWindow; + nsCOMPtr newWindow; rv = appShell->CreateTopLevelWindow( nsnull, url, PR_TRUE, - newWindow, + *getter_AddRefs(newWindow), nsnull, this, 0, 0 ); if ( NS_SUCCEEDED( rv ) ) { mWindow = newWindow; - NS_RELEASE( newWindow ); } else { DEBUG_PRINTF( PR_STDOUT, "Error creating download progress dialog, rv=0x%X\n", (int)rv ); } diff --git a/xpinstall/src/nsInstallProgressDialog.cpp b/xpinstall/src/nsInstallProgressDialog.cpp index 056925a25bb2..f9a12a5ce395 100644 --- a/xpinstall/src/nsInstallProgressDialog.cpp +++ b/xpinstall/src/nsInstallProgressDialog.cpp @@ -236,12 +236,11 @@ nsInstallProgressDialog::Open() if ( NS_SUCCEEDED(rv) ) { - nsIWebShellWindow *newWindow; - + nsCOMPtr newWindow; rv = appShell->CreateTopLevelWindow( nsnull, url, PR_TRUE, - newWindow, + *getter_AddRefs(newWindow), nsnull, this, // callbacks?? 0, @@ -249,8 +248,7 @@ nsInstallProgressDialog::Open() if ( NS_SUCCEEDED( rv ) ) { - mWindow = newWindow; - NS_RELEASE( newWindow ); + mWindow = newWindow; // ownership? if (mWindow != nsnull) mWindow->Show(PR_TRUE);