Bug 563556 - Cleanup nsGlobalWindow's alert/confirm/prompt. r=jst

This commit is contained in:
Justin Dolske 2010-05-13 15:26:10 -07:00
parent 58222a942d
commit e9a8268fd1
2 changed files with 27 additions and 40 deletions

View File

@ -128,7 +128,6 @@
#include "nsIPresShell.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIProgrammingLanguage.h"
#include "nsIAuthPrompt.h"
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptSecurityManager.h"
@ -138,6 +137,7 @@
#include "nsISelectionController.h"
#include "nsISelection.h"
#include "nsIPrompt.h"
#include "nsIPromptService.h"
#include "nsIWebNavigation.h"
#include "nsIWebBrowser.h"
#include "nsIWebBrowserChrome.h"
@ -4245,9 +4245,6 @@ nsGlobalWindow::Alert(const nsAString& aString)
{
FORWARD_TO_OUTER(Alert, (aString), NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mDocShell));
NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE);
// Reset popup state while opening a modal dialog, and firing events
// about the dialog, to prevent the current state from being active
// the whole time a modal dialog is open.
@ -4272,7 +4269,11 @@ nsGlobalWindow::Alert(const nsAString& aString)
nsAutoString final;
nsContentUtils::StripNullChars(*str, final);
return prompter->Alert(title.get(), final.get());
nsresult rv;
nsCOMPtr<nsIPromptService> promptSvc = do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
return promptSvc->Alert(this, title.get(), final.get());
}
NS_IMETHODIMP
@ -4280,9 +4281,6 @@ nsGlobalWindow::Confirm(const nsAString& aString, PRBool* aReturn)
{
FORWARD_TO_OUTER(Confirm, (aString, aReturn), NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mDocShell));
NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE);
// Reset popup state while opening a modal dialog, and firing events
// about the dialog, to prevent the current state from being active
// the whole time a modal dialog is open.
@ -4302,42 +4300,24 @@ nsGlobalWindow::Confirm(const nsAString& aString, PRBool* aReturn)
nsAutoString final;
nsContentUtils::StripNullChars(aString, final);
return prompter->Confirm(title.get(), final.get(),
aReturn);
nsresult rv;
nsCOMPtr<nsIPromptService> promptSvc = do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
return promptSvc->Confirm(this, title.get(), final.get(), aReturn);
}
NS_IMETHODIMP
nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial,
const nsAString& aTitle, PRUint32 aSavePassword,
nsAString& aReturn)
{
// We don't use "aTitle" because we ignore the 3rd (title) argument to
// prompt(). IE and Opera ignore it too. See Mozilla bug 334893.
SetDOMStringToNull(aReturn);
// This code depends on aSavePassword being defaulted to
// nsIAuthPrompt::SAVE_PASSWORD_NEVER, which happens to have the
// value 0. If that ever changes, this code needs to deal!
PR_STATIC_ASSERT(nsIAuthPrompt::SAVE_PASSWORD_NEVER == 0);
nsresult rv;
nsCOMPtr<nsIWindowWatcher> wwatch =
do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAuthPrompt> prompter;
wwatch->GetNewAuthPrompter(this, getter_AddRefs(prompter));
NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE);
// Reset popup state while opening a modal dialog, and firing events
// about the dialog, to prevent the current state from being active
// the whole time a modal dialog is open.
nsAutoPopupStatePusher popupStatePusher(openAbused, PR_TRUE);
PRBool b;
nsXPIDLString uniResult;
// Before bringing up the window, unsuppress painting and flush
// pending reflows.
EnsureReflowFlushAndPaint();
@ -4351,13 +4331,22 @@ nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial,
nsContentUtils::StripNullChars(aMessage, fixedMessage);
nsContentUtils::StripNullChars(aInitial, fixedInitial);
rv = prompter->Prompt(title.get(), fixedMessage.get(), nsnull,
aSavePassword, fixedInitial.get(),
getter_Copies(uniResult), &b);
nsresult rv;
nsCOMPtr<nsIPromptService> promptSvc = do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (uniResult && b) {
aReturn.Assign(uniResult);
// Pass in the default value, if any.
PRUnichar *inoutValue = ToNewUnicode(fixedInitial);
PRBool ok, dummy;
rv = promptSvc->Prompt(this, title.get(), fixedMessage.get(),
&inoutValue, nsnull, &dummy, &ok);
NS_ENSURE_SUCCESS(rv, rv);
nsAdoptingString outValue(inoutValue);
if (ok && outValue) {
aReturn.Assign(outValue);
}
return rv;

View File

@ -44,7 +44,7 @@ interface nsIControllers;
interface nsIDOMLocation;
interface nsIVariant;
[scriptable, uuid(f18e491b-0c1a-4a9d-9281-32f39fa2d637)]
[scriptable, uuid(52d034f1-f1a6-4be7-adc9-b39fa7df51de)]
interface nsIDOMWindowInternal : nsIDOMWindow2
{
readonly attribute nsIDOMWindowInternal window;
@ -126,9 +126,7 @@ interface nsIDOMWindowInternal : nsIDOMWindow2
// prompt() should return a null string if cancel is pressed
DOMString prompt([optional] in DOMString aMessage,
[optional] in DOMString aInitial,
[optional] in DOMString aTitle,
[optional] in unsigned long aSavePassword);
[optional] in DOMString aInitial);
void focus();
void blur();