From 1ac6c0c622e84299875c978aabf69f13ca5575ae Mon Sep 17 00:00:00 2001 From: Justin Dolske Date: Wed, 16 Jun 2010 17:06:17 -0700 Subject: [PATCH] Bug 563274 - Overhaul nsIPrompt-related prompting code. r=gavin, sr=bs --HG-- rename : toolkit/content/commonDialog.css => toolkit/components/prompts/content/commonDialog.css rename : toolkit/content/commonDialog.js => toolkit/components/prompts/content/commonDialog.js rename : toolkit/content/commonDialog.xul => toolkit/components/prompts/content/commonDialog.xul rename : toolkit/content/selectDialog.js => toolkit/components/prompts/content/selectDialog.js rename : toolkit/content/selectDialog.xul => toolkit/components/prompts/content/selectDialog.xul --- .../components/build/nsEmbeddingModule.cpp | 55 -- .../windowwatcher/public/Makefile.in | 1 - .../public/nsIAuthPromptWrapper.idl | 63 -- .../components/windowwatcher/src/Makefile.in | 3 +- .../components/windowwatcher/src/nsPrompt.cpp | 590 ------------- .../components/windowwatcher/src/nsPrompt.h | 108 --- .../windowwatcher/src/nsPromptService.cpp | 786 ------------------ .../windowwatcher/src/nsPromptService.h | 79 -- .../windowwatcher/src/nsWindowWatcher.cpp | 69 +- .../windowwatcher/src/nsWindowWatcher.h | 5 +- netwerk/base/src/nsPACMan.cpp | 9 +- netwerk/build/nsNetCID.h | 18 - netwerk/test/unit/test_authentication.js | 2 +- netwerk/test/unit/test_authpromptwrapper.js | 5 +- .../passwordmgr/src/nsLoginManagerPrompter.js | 3 +- .../prompts}/content/commonDialog.css | 2 +- .../prompts/content/commonDialog.js | 365 ++++++++ .../prompts}/content/commonDialog.xul | 8 +- .../prompts/content/selectDialog.js | 102 +++ .../prompts}/content/selectDialog.xul | 5 +- toolkit/components/prompts/jar.mn | 6 + toolkit/components/prompts/src/nsPrompter.js | 717 +++++++++++++++- .../prompts/test/test_modal_prompts.html | 2 +- toolkit/content/commonDialog.js | 389 --------- toolkit/content/jar.mn | 5 - toolkit/content/selectDialog.js | 159 ---- .../en-US/chrome/global/commonDialog.dtd | 1 - 27 files changed, 1226 insertions(+), 2331 deletions(-) delete mode 100644 embedding/components/windowwatcher/public/nsIAuthPromptWrapper.idl delete mode 100644 embedding/components/windowwatcher/src/nsPrompt.cpp delete mode 100644 embedding/components/windowwatcher/src/nsPrompt.h delete mode 100644 embedding/components/windowwatcher/src/nsPromptService.cpp delete mode 100644 embedding/components/windowwatcher/src/nsPromptService.h rename toolkit/{ => components/prompts}/content/commonDialog.css (97%) create mode 100644 toolkit/components/prompts/content/commonDialog.js rename toolkit/{ => components/prompts}/content/commonDialog.xul (90%) create mode 100644 toolkit/components/prompts/content/selectDialog.js rename toolkit/{ => components/prompts}/content/selectDialog.xul (93%) create mode 100644 toolkit/components/prompts/jar.mn delete mode 100644 toolkit/content/commonDialog.js delete mode 100644 toolkit/content/selectDialog.js diff --git a/embedding/components/build/nsEmbeddingModule.cpp b/embedding/components/build/nsEmbeddingModule.cpp index dc6f1a21a9e..e0cac05ee3d 100644 --- a/embedding/components/build/nsEmbeddingModule.cpp +++ b/embedding/components/build/nsEmbeddingModule.cpp @@ -37,7 +37,6 @@ #include "nsIGenericFactory.h" #include "nsDialogParamBlock.h" -#include "nsPromptService.h" #include "nsWindowWatcher.h" #include "nsAppStartupNotifier.h" #include "nsFind.h" @@ -48,7 +47,6 @@ #include "nsCommandParams.h" #include "nsCommandGroup.h" #include "nsBaseCommandController.h" -#include "nsPrompt.h" #include "nsNetCID.h" #include "nsEmbedCID.h" @@ -70,57 +68,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCommandParams, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseCommandController) -#define NS_DEFAULTPROMPT_CLASSNAME \ - "nsDefaultPrompt" -#define NS_DEFAULTPROMPT_CID \ -{ /* 2e41ada0-62b7-4902-b9a6-e4542aa458ba */ \ - 0x2e41ada0, \ - 0x62b7, \ - 0x4902, \ - {0xb9, 0xa6, 0xe4, 0x54, 0x2a, 0xa4, 0x58, 0xba} \ -} - -#define NS_DEFAULTAUTHPROMPT_CLASSNAME \ - "nsDefaultAuthPrompt" -#define NS_DEFAULTAUTHPROMPT_CID \ -{ /* ca200860-4696-40d7-88fa-4490d423a8ef */ \ - 0xca200860, \ - 0x4696, \ - 0x40d7, \ - {0x88, 0xfa, 0x44, 0x90, 0xd4, 0x23, 0xa8, 0xef} \ -} - -static NS_METHOD -nsDefaultPromptConstructor(nsISupports *outer, const nsIID &iid, void **result) -{ - if (outer) - return NS_ERROR_NO_AGGREGATION; - - nsCOMPtr prompt; - nsresult rv = NS_NewPrompter(getter_AddRefs(prompt), nsnull); - if (NS_FAILED(rv)) - return rv; - - return prompt->QueryInterface(iid, result); -} - -static NS_METHOD -nsDefaultAuthPromptConstructor(nsISupports *outer, const nsIID &iid, void **result) -{ - if (outer) - return NS_ERROR_NO_AGGREGATION; - - nsCOMPtr prompt; - nsresult rv = NS_NewAuthPrompter(getter_AddRefs(prompt), nsnull); - if (NS_FAILED(rv)) - return rv; - - return prompt->QueryInterface(iid, result); -} - #ifdef MOZ_XUL NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPromptService, Init) #ifdef NS_PRINTING #ifndef WINCE NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init) @@ -132,7 +81,6 @@ static const nsModuleComponentInfo gComponents[] = { #ifdef MOZ_XUL { "Dialog ParamBlock", NS_DIALOGPARAMBLOCK_CID, NS_DIALOGPARAMBLOCK_CONTRACTID, nsDialogParamBlockConstructor }, - { "Prompt Service", NS_PROMPTSERVICE_CID, NS_PROMPTSERVICE_CONTRACTID, nsPromptServiceConstructor }, #ifdef NS_PRINTING #ifndef WINCE { "Printing Prompt Service", NS_PRINTINGPROMPTSERVICE_CID, NS_PRINTINGPROMPTSERVICE_CONTRACTID, nsPrintingPromptServiceConstructor }, @@ -140,7 +88,6 @@ static const nsModuleComponentInfo gComponents[] = { #endif #endif { "Window Watcher", NS_WINDOWWATCHER_CID, NS_WINDOWWATCHER_CONTRACTID, nsWindowWatcherConstructor }, - { "Window Watcher", NS_WINDOWWATCHER_CID, NS_AUTHPROMPT_ADAPTER_FACTORY_CONTRACTID, nsWindowWatcherConstructor }, { "Find", NS_FIND_CID, NS_FIND_CONTRACTID, nsFindConstructor }, { "WebBrowserFind", NS_WEB_BROWSER_FIND_CID, NS_WEB_BROWSER_FIND_CONTRACTID, nsWebBrowserFindConstructor }, { NS_APPSTARTUPNOTIFIER_CLASSNAME, NS_APPSTARTUPNOTIFIER_CID, NS_APPSTARTUPNOTIFIER_CONTRACTID, nsAppStartupNotifierConstructor }, @@ -150,8 +97,6 @@ static const nsModuleComponentInfo gComponents[] = { { "Command Params", NS_COMMAND_PARAMS_CID, NS_COMMAND_PARAMS_CONTRACTID, nsCommandParamsConstructor }, { "Command Group", NS_CONTROLLER_COMMAND_GROUP_CID, NS_CONTROLLER_COMMAND_GROUP_CONTRACTID, nsControllerCommandGroupConstructor }, { "Base Command Controller", NS_BASECOMMANDCONTROLLER_CID, NS_BASECOMMANDCONTROLLER_CONTRACTID, nsBaseCommandControllerConstructor }, - { NS_DEFAULTPROMPT_CLASSNAME, NS_DEFAULTPROMPT_CID, NS_DEFAULTPROMPT_CONTRACTID, nsDefaultPromptConstructor }, - { NS_DEFAULTAUTHPROMPT_CLASSNAME, NS_DEFAULTAUTHPROMPT_CID, NS_DEFAULTAUTHPROMPT_CONTRACTID, nsDefaultAuthPromptConstructor } }; NS_IMPL_NSGETMODULE(embedcomponents, gComponents) diff --git a/embedding/components/windowwatcher/public/Makefile.in b/embedding/components/windowwatcher/public/Makefile.in index d257366a1d5..1f27487e41f 100644 --- a/embedding/components/windowwatcher/public/Makefile.in +++ b/embedding/components/windowwatcher/public/Makefile.in @@ -55,7 +55,6 @@ XPIDLSRCS = nsIDialogParamBlock.idl \ nsIPromptService2.idl \ nsPIPromptService.idl \ nsPIWindowWatcher.idl \ - nsIAuthPromptWrapper.idl \ nsIPromptFactory.idl \ $(NULL) diff --git a/embedding/components/windowwatcher/public/nsIAuthPromptWrapper.idl b/embedding/components/windowwatcher/public/nsIAuthPromptWrapper.idl deleted file mode 100644 index 8bee129b2fa..00000000000 --- a/embedding/components/windowwatcher/public/nsIAuthPromptWrapper.idl +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIAuthPrompt.idl" - -interface nsIPrompt; - -/** - * nsIAuthPromptWrapper - * - * An override of nsIAuthPrompt which performs some action - * on the data going through nsIAuthPrompt methods. Persisting - * data from the prompts and using it to pre-fill subsequent prompts - * would be one such action. - * - * @status - */ - -[scriptable, uuid(7708b352-35e0-47f6-a1c2-ccdd3319d0ab)] -interface nsIAuthPromptWrapper : nsIAuthPrompt -{ - /** - * setPromptDialogs - * - * @param dialogs the dialog implementation which will - * be used to display the prompts - */ - void setPromptDialogs(in nsIPrompt dialogs); -}; diff --git a/embedding/components/windowwatcher/src/Makefile.in b/embedding/components/windowwatcher/src/Makefile.in index eed0b252e96..ff355a648db 100644 --- a/embedding/components/windowwatcher/src/Makefile.in +++ b/embedding/components/windowwatcher/src/Makefile.in @@ -47,7 +47,7 @@ LIBRARY_NAME = windowwatcher_s LIBXUL_LIBRARY = 1 -CPPSRCS = nsPrompt.cpp \ +CPPSRCS = \ nsWWJSUtils.cpp \ nsWindowWatcher.cpp \ nsAutoWindowStateHelper.cpp \ @@ -55,7 +55,6 @@ CPPSRCS = nsPrompt.cpp \ ifdef MOZ_XUL CPPSRCS += nsDialogParamBlock.cpp \ - nsPromptService.cpp \ $(NULL) endif diff --git a/embedding/components/windowwatcher/src/nsPrompt.cpp b/embedding/components/windowwatcher/src/nsPrompt.cpp deleted file mode 100644 index e8e405827dd..00000000000 --- a/embedding/components/windowwatcher/src/nsPrompt.cpp +++ /dev/null @@ -1,590 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sts=2 sw=2 et cin: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Google Inc. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIServiceManager.h" -#include "nsIAuthPromptWrapper.h" -#include "nsIAuthInformation.h" -#include "nsPrompt.h" -#include "nsReadableUtils.h" -#include "nsDependentString.h" -#include "nsIStringBundle.h" -#include "nsIChannel.h" -#include "nsIURI.h" -#include "nsEmbedCID.h" -#include "nsNetCID.h" -#include "nsPIDOMWindow.h" -#include "nsIPromptFactory.h" -#include "nsIProxiedChannel.h" -#include "nsIProxyInfo.h" -#include "nsIIDNService.h" -#include "nsNetUtil.h" -#include "nsPromptUtils.h" -#include "nsIPrefService.h" -#include "nsIPrefLocalizedString.h" - - -nsresult -NS_NewPrompter(nsIPrompt **result, nsIDOMWindow *aParent) -{ - nsresult rv; - *result = 0; - - nsPrompt *prompter = new nsPrompt(aParent); - if (!prompter) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(prompter); - rv = prompter->Init(); - if (NS_FAILED(rv)) { - NS_RELEASE(prompter); - return rv; - } - - *result = prompter; - return NS_OK; -} - -nsresult -NS_NewAuthPrompter(nsIAuthPrompt **result, nsIDOMWindow *aParent) -{ - nsresult rv; - nsCOMPtr factory = - do_GetService(NS_PWMGR_AUTHPROMPTFACTORY); - if (factory) { - // We just delegate everything to the pw mgr if we can - rv = factory->GetPrompt(aParent, - NS_GET_IID(nsIAuthPrompt), - reinterpret_cast(result)); - // If the password manager doesn't support the interface, fall back to the - // old way of doing things. This will allow older apps that haven't updated - // to work still. - if (rv != NS_NOINTERFACE) - return rv; - } - - *result = 0; - - nsPrompt *prompter = new nsPrompt(aParent); - if (!prompter) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(prompter); - rv = prompter->Init(); - if (NS_FAILED(rv)) { - NS_RELEASE(prompter); - return rv; - } - - *result = prompter; - // wrap the base prompt in an nsIAuthPromptWrapper, if available - // the impl used here persists prompt data and pre-fills the dialogs - nsCOMPtr siPrompt = - do_CreateInstance("@mozilla.org/wallet/single-sign-on-prompt;1"); - if (siPrompt) { - // then single sign-on is installed - rv = siPrompt->SetPromptDialogs(prompter); - if (NS_SUCCEEDED(rv)) { - *result = siPrompt; - NS_RELEASE(prompter); // siPrompt is a strong owner - NS_ADDREF(*result); - } - } - return NS_OK; -} - -nsresult -NS_NewAuthPrompter2(nsIAuthPrompt2 **result, nsIDOMWindow *aParent) -{ - nsresult rv; - - nsCOMPtr factory = - do_GetService(NS_PWMGR_AUTHPROMPTFACTORY); - if (factory) { - // We just delegate everything to the pw mgr. - rv = factory->GetPrompt(aParent, - NS_GET_IID(nsIAuthPrompt2), - reinterpret_cast(result)); - // Bug 403115. Don't suppress error if interface isn't supported. - if (NS_SUCCEEDED(rv) || rv == NS_NOINTERFACE) - return rv; - } - - *result = 0; - - nsPrompt *prompter = new nsPrompt(aParent); - if (!prompter) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(prompter); - rv = prompter->Init(); - if (NS_FAILED(rv)) { - NS_RELEASE(prompter); - return rv; - } - - *result = prompter; - return NS_OK; -} - -NS_IMPL_THREADSAFE_ISUPPORTS3(nsPrompt, nsIPrompt, nsIAuthPrompt, nsIAuthPrompt2) - -nsPrompt::nsPrompt(nsIDOMWindow *aParent) - : mParent(aParent) -{ -#ifdef DEBUG - { - nsCOMPtr win(do_QueryInterface(aParent)); - - NS_ASSERTION(!win || win->IsOuterWindow(), - "Inner window passed as nsPrompt parent!"); - } -#endif -} - -nsresult -nsPrompt::Init() -{ - mPromptService = do_GetService(NS_PROMPTSERVICE_CONTRACTID); - mPromptService2 = do_QueryInterface(mPromptService); - // A null mPromptService2 is not fatal, we have to deal with that - // (for compatibility with embeddors who only implement the old version) - return mPromptService ? NS_OK : NS_ERROR_FAILURE; -} - -//***************************************************************************** -// nsPrompt::nsIPrompt -//***************************************************************************** - -NS_IMETHODIMP -nsPrompt::Alert(const PRUnichar* dialogTitle, - const PRUnichar* text) -{ - return mPromptService->Alert(mParent, dialogTitle, text); -} - -NS_IMETHODIMP -nsPrompt::AlertCheck(const PRUnichar* dialogTitle, - const PRUnichar* text, - const PRUnichar* checkMsg, - PRBool *checkValue) -{ - return mPromptService->AlertCheck(mParent, dialogTitle, text, checkMsg, - checkValue); -} - -NS_IMETHODIMP -nsPrompt::Confirm(const PRUnichar* dialogTitle, - const PRUnichar* text, - PRBool *_retval) -{ - return mPromptService->Confirm(mParent, dialogTitle, text, _retval); -} - -NS_IMETHODIMP -nsPrompt::ConfirmCheck(const PRUnichar* dialogTitle, - const PRUnichar* text, - const PRUnichar* checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - return mPromptService->ConfirmCheck(mParent, dialogTitle, text, checkMsg, - checkValue, _retval); -} - -NS_IMETHODIMP -nsPrompt::ConfirmEx(const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUint32 buttonFlags, - const PRUnichar *button0Title, - const PRUnichar *button1Title, - const PRUnichar *button2Title, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRInt32 *buttonPressed) -{ - return mPromptService->ConfirmEx(mParent, dialogTitle, text, buttonFlags, - button0Title, button1Title, button2Title, - checkMsg, checkValue, buttonPressed); -} - -NS_IMETHODIMP -nsPrompt::Prompt(const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **answer, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - return mPromptService->Prompt(mParent, dialogTitle, text, answer, checkMsg, - checkValue, _retval); -} - -NS_IMETHODIMP -nsPrompt::PromptUsernameAndPassword(const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **username, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - return mPromptService->PromptUsernameAndPassword(mParent, dialogTitle, text, - username, password, - checkMsg, checkValue, - _retval); -} - -NS_IMETHODIMP -nsPrompt::PromptPassword(const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - return mPromptService->PromptPassword(mParent, dialogTitle, text, password, - checkMsg, checkValue, _retval); -} - -NS_IMETHODIMP -nsPrompt::Select(const PRUnichar *dialogTitle, - const PRUnichar* inMsg, - PRUint32 inCount, - const PRUnichar **inList, - PRInt32 *outSelection, - PRBool *_retval) -{ - return mPromptService->Select(mParent, dialogTitle, inMsg, inCount, inList, - outSelection, _retval); -} - -//***************************************************************************** -// nsPrompt::nsIAuthPrompt -// This implementation serves as glue between nsIAuthPrompt and nsIPrompt -// when a single-signon was not available. -//***************************************************************************** - -NS_IMETHODIMP -nsPrompt::Prompt(const PRUnichar* dialogTitle, - const PRUnichar* text, - const PRUnichar* passwordRealm, - PRUint32 savePassword, - const PRUnichar* defaultText, - PRUnichar* *result, - PRBool *_retval) -{ - // Ignore passwordRealm and savePassword - if (defaultText) { - *result = ToNewUnicode(nsDependentString(defaultText)); - - if (!*result) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - - return mPromptService->Prompt(mParent, dialogTitle, text, result, nsnull, - nsnull, _retval); -} - -NS_IMETHODIMP -nsPrompt::PromptUsernameAndPassword(const PRUnichar* dialogTitle, - const PRUnichar* text, - const PRUnichar* passwordRealm, - PRUint32 savePassword, - PRUnichar* *user, - PRUnichar* *pwd, - PRBool *_retval) -{ - // Ignore passwordRealm and savePassword - return mPromptService->PromptUsernameAndPassword(mParent, dialogTitle, text, - user, pwd, nsnull, nsnull, - _retval); -} - -NS_IMETHODIMP -nsPrompt::PromptPassword(const PRUnichar* dialogTitle, - const PRUnichar* text, - const PRUnichar* passwordRealm, - PRUint32 savePassword, - PRUnichar* *pwd, - PRBool *_retval) -{ - // Ignore passwordRealm and savePassword - return mPromptService->PromptPassword(mParent, dialogTitle, text, pwd, - nsnull, nsnull, _retval); -} -NS_IMETHODIMP -nsPrompt::PromptAuth(nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - PRBool* retval) -{ - if (mPromptService2) { - return mPromptService2->PromptAuth(mParent, aChannel, - aLevel, aAuthInfo, - nsnull, nsnull, retval); - } - - return PromptPasswordAdapter(mPromptService, mParent, aChannel, - aLevel, aAuthInfo, nsnull, nsnull, retval); -} - -NS_IMETHODIMP -nsPrompt::AsyncPromptAuth(nsIChannel* aChannel, - nsIAuthPromptCallback* aCallback, - nsISupports* aContext, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - nsICancelable** retval) -{ - if (mPromptService2) { - return mPromptService2->AsyncPromptAuth(mParent, aChannel, - aCallback, aContext, - aLevel, aAuthInfo, - nsnull, nsnull, retval); - } - - // Tell the caller to use the sync version - return NS_ERROR_NOT_IMPLEMENTED; -} - -static nsresult -MakeDialogText(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo, - nsXPIDLString& message) -{ - nsresult rv; - nsCOMPtr bundleSvc = - do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr bundle; - rv = bundleSvc->CreateBundle("chrome://global/locale/commonDialogs.properties", - getter_AddRefs(bundle)); - NS_ENSURE_SUCCESS(rv, rv); - - // figure out what message to display... - nsCAutoString host; - PRInt32 port; - NS_GetAuthHostPort(aChannel, aAuthInfo, PR_FALSE, host, &port); - - nsAutoString displayHost; - CopyUTF8toUTF16(host, displayHost); - - nsCOMPtr uri; - aChannel->GetURI(getter_AddRefs(uri)); - - nsCAutoString scheme; - uri->GetScheme(scheme); - - nsAutoString username; - aAuthInfo->GetUsername(username); - - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - PRBool proxyAuth = (flags & nsIAuthInformation::AUTH_PROXY) != 0; - - nsAutoString realm; - aAuthInfo->GetRealm(realm); - // Trim obnoxiously long realms. - if (realm.Length() > 150) { - realm.Truncate(150); - - // Append "..." (or localized equivalent). Yay complexity. - nsAutoString ellipsis; - nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefs) { - nsCOMPtr prefString; - rv = prefs->GetComplexValue("intl.ellipsis", - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(prefString)); - if (prefString) - prefString->ToString(getter_Copies(ellipsis)); - } - if (ellipsis.IsEmpty()) - ellipsis.AssignLiteral("..."); - - realm.Append(ellipsis); - } - - // Append the port if it was specified - if (port != -1) { - displayHost.Append(PRUnichar(':')); - displayHost.AppendInt(port); - } - - NS_NAMED_LITERAL_STRING(proxyText, "EnterLoginForProxy"); - NS_NAMED_LITERAL_STRING(originText, "EnterLoginForRealm"); - NS_NAMED_LITERAL_STRING(noRealmText, "EnterUserPasswordFor"); - NS_NAMED_LITERAL_STRING(passwordText, "EnterPasswordFor"); - - const PRUnichar *text; - if (proxyAuth) { - text = proxyText.get(); - } else { - text = originText.get(); - - // prepend "scheme://" - nsAutoString schemeU; - CopyASCIItoUTF16(scheme, schemeU); - schemeU.AppendLiteral("://"); - displayHost.Insert(schemeU, 0); - } - - const PRUnichar *strings[] = { realm.get(), displayHost.get() }; - PRUint32 count = NS_ARRAY_LENGTH(strings); - - if (flags & nsIAuthInformation::ONLY_PASSWORD) { - text = passwordText.get(); - strings[0] = username.get(); - } else if (!proxyAuth && realm.IsEmpty()) { - text = noRealmText.get(); - count--; - strings[0] = strings[1]; - } - - rv = bundle->FormatStringFromName(text, strings, count, getter_Copies(message)); - return rv; -} - -/* static */ nsresult -nsPrompt::PromptPasswordAdapter(nsIPromptService* aService, - nsIDOMWindow* aParent, - nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - PRBool* retval) -{ - // construct the message string - nsXPIDLString message; - MakeDialogText(aChannel, aAuthInfo, message); - - nsAutoString defaultUser, defaultDomain, defaultPass; - aAuthInfo->GetUsername(defaultUser); - aAuthInfo->GetDomain(defaultDomain); - aAuthInfo->GetPassword(defaultPass); - - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - - if ((flags & nsIAuthInformation::NEED_DOMAIN) && !defaultDomain.IsEmpty()) { - defaultDomain.Append(PRUnichar('\\')); - defaultUser.Insert(defaultDomain, 0); - } - - // NOTE: Allocation failure is not fatal here (just default to empty string - // if allocation fails) - PRUnichar *user = ToNewUnicode(defaultUser), - *pass = ToNewUnicode(defaultPass); - nsresult rv; - if (flags & nsIAuthInformation::ONLY_PASSWORD) - rv = aService->PromptPassword(aParent, nsnull, message.get(), - &pass, aCheckLabel, - aCheckValue, retval); - else - rv = aService->PromptUsernameAndPassword(aParent, nsnull, message.get(), - &user, &pass, aCheckLabel, - aCheckValue, retval); - - nsAdoptingString userStr(user); - nsAdoptingString passStr(pass); - NS_SetAuthInfo(aAuthInfo, userStr, passStr); - - return rv; -} - -NS_IMPL_THREADSAFE_ISUPPORTS1(AuthPromptWrapper, nsIAuthPrompt2) - -NS_IMETHODIMP -AuthPromptWrapper::PromptAuth(nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - PRBool* retval) -{ - nsCAutoString keyUTF8; - NS_GetAuthKey(aChannel, aAuthInfo, keyUTF8); - - NS_ConvertUTF8toUTF16 key(keyUTF8); - - nsXPIDLString text; - MakeDialogText(aChannel, aAuthInfo, text); - - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - - nsresult rv; - nsXPIDLString user, password; - if (flags & nsIAuthInformation::ONLY_PASSWORD) { - rv = mAuthPrompt->PromptPassword(nsnull, text.get(), key.get(), - nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, - getter_Copies(password), retval); - if (NS_SUCCEEDED(rv) && *retval) { - NS_ASSERTION(password, "password must not be null if retval is true"); - aAuthInfo->SetPassword(password); - } - } else { - rv = mAuthPrompt->PromptUsernameAndPassword(nsnull, text.get(), key.get(), - nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, - getter_Copies(user), - getter_Copies(password), - retval); - if (NS_SUCCEEDED(rv) && *retval) { - NS_ASSERTION(user && password, "out params must be nonnull"); - NS_SetAuthInfo(aAuthInfo, user, password); - } - } - return rv; -} - -NS_IMETHODIMP -AuthPromptWrapper::AsyncPromptAuth(nsIChannel*, - nsIAuthPromptCallback*, - nsISupports*, - PRUint32, - nsIAuthInformation*, - nsICancelable**) -{ - // There is no way to implement this here. Just tell the caller - // to fall back to the synchronous version. - return NS_ERROR_NOT_IMPLEMENTED; -} - - - diff --git a/embedding/components/windowwatcher/src/nsPrompt.h b/embedding/components/windowwatcher/src/nsPrompt.h deleted file mode 100644 index fbac461afb3..00000000000 --- a/embedding/components/windowwatcher/src/nsPrompt.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCOMPtr.h" -#include "nsIDOMWindow.h" -#include "nsIPrompt.h" -#include "nsIAuthPrompt.h" -#include "nsIAuthPrompt2.h" -#include "nsIPromptService.h" -#include "nsIPromptService2.h" - -class nsPrompt : public nsIPrompt, - public nsIAuthPrompt, - public nsIAuthPrompt2 { - -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPROMPT - NS_DECL_NSIAUTHPROMPT - NS_DECL_NSIAUTHPROMPT2 - - nsPrompt(nsIDOMWindow *window); - virtual ~nsPrompt() {} - - nsresult Init(); - - /** - * This helper method can be used to implement nsIAuthPrompt2's - * PromptPassword function using nsIPromptService (as opposed to - * nsIPromptService2). - */ - static nsresult PromptPasswordAdapter(nsIPromptService* aService, - nsIDOMWindow* aParent, - nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - PRBool* retval); - -protected: - nsCOMPtr mParent; - nsCOMPtr mPromptService; - // This is the new prompt service version. May be null. - nsCOMPtr mPromptService2; -}; - -/** - * A class that wraps an nsIAuthPrompt so that it can be used as an - * nsIAuthPrompt2. - */ -class AuthPromptWrapper : public nsIAuthPrompt2 -{ - public: - AuthPromptWrapper(nsIAuthPrompt* aAuthPrompt) : - mAuthPrompt(aAuthPrompt) {} - - NS_DECL_ISUPPORTS - NS_DECL_NSIAUTHPROMPT2 - - private: - ~AuthPromptWrapper() {} - - nsCOMPtr mAuthPrompt; -}; - -nsresult -NS_NewPrompter(nsIPrompt **result, nsIDOMWindow *aParent); - -nsresult -NS_NewAuthPrompter(nsIAuthPrompt **result, nsIDOMWindow *aParent); - -nsresult -NS_NewAuthPrompter2(nsIAuthPrompt2 **result, nsIDOMWindow *aParent); diff --git a/embedding/components/windowwatcher/src/nsPromptService.cpp b/embedding/components/windowwatcher/src/nsPromptService.cpp deleted file mode 100644 index a5473aa735d..00000000000 --- a/embedding/components/windowwatcher/src/nsPromptService.cpp +++ /dev/null @@ -1,786 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsPromptService.h" -#include "nsPrompt.h" - -#include "nsDialogParamBlock.h" -#include "nsIComponentManager.h" -#include "nsIDialogParamBlock.h" -#include "nsIDOMWindow.h" -#include "nsPIDOMWindow.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMEvent.h" -#include "nsIPrivateDOMEvent.h" -#include "nsIDOMDocumentEvent.h" -#include "nsIServiceManager.h" -#include "nsISupportsUtils.h" -#include "nsString.h" -#include "nsIStringBundle.h" -#include "nsXPIDLString.h" -#include "nsISound.h" - -static const char kPromptURL[] = "chrome://global/content/commonDialog.xul"; -static const char kSelectPromptURL[] = "chrome://global/content/selectDialog.xul"; -static const char kQuestionIconClass[] = "question-icon"; -static const char kAlertIconClass[] = "alert-icon"; -// We include question-icon for backwards compatibility -static const char kAuthenticationIconClass[] = "authentication-icon question-icon"; - -#define kCommonDialogsProperties "chrome://global/locale/commonDialogs.properties" - -/**************************************************************** - ************************* ParamBlock *************************** - ****************************************************************/ - -class ParamBlock { - -public: - ParamBlock() { - mBlock = 0; - } - ~ParamBlock() { - NS_IF_RELEASE(mBlock); - } - nsresult Init() { - return CallCreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &mBlock); - } - nsIDialogParamBlock * operator->() const { return mBlock; } - operator nsIDialogParamBlock * const () { return mBlock; } - -private: - nsIDialogParamBlock *mBlock; -}; - -/**************************************************************** - ************************ nsPromptService *********************** - ****************************************************************/ - -NS_IMPL_ISUPPORTS3(nsPromptService, nsIPromptService, nsIPromptService2, - nsPIPromptService) - -nsPromptService::nsPromptService() { -} - -nsPromptService::~nsPromptService() { -} - -nsresult -nsPromptService::Init() -{ - nsresult rv; - mWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - return rv; -} - -NS_IMETHODIMP -nsPromptService::Alert(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Alert", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt(eNumberButtons, 1); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - nsString url; - NS_ConvertASCIItoUTF16 styleClass(kAlertIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetString(eOpeningSound, NS_SYSSOUND_ALERT_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_ALERT_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - - return rv; -} - - - -NS_IMETHODIMP -nsPromptService::AlertCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - const PRUnichar *checkMsg, PRBool *checkValue) - -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // checkValue is an inout parameter, so we don't have to set it - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Alert", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt( eNumberButtons,1 ); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - NS_ConvertASCIItoUTF16 styleClass(kAlertIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetString(eCheckboxMsg, checkMsg); - block->SetInt(eCheckboxState, *checkValue); - block->SetString(eOpeningSound, NS_SYSSOUND_ALERT_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_ALERT_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - block->GetInt(eCheckboxState, checkValue); - - return rv; -} - -NS_IMETHODIMP -nsPromptService::Confirm(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - PRBool *_retval) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel - *_retval = PR_FALSE; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Confirm", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - // Stuff in Parameters - block->SetInt(eNumberButtons, 2); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 buttonPressed = 0; - block->GetInt(eButtonPressed, &buttonPressed); - *_retval = buttonPressed ? PR_FALSE : PR_TRUE; - - return rv; -} - -NS_IMETHODIMP -nsPromptService::ConfirmCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - const PRUnichar *checkMsg, PRBool *checkValue, - PRBool *_retval) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel. checkValue is an inout parameter, so we don't have to set it - *_retval = PR_FALSE; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("ConfirmCheck", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt( eNumberButtons,2 ); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetString(eCheckboxMsg, checkMsg); - block->SetInt(eCheckboxState, *checkValue); - block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 tempInt = 0; - block->GetInt(eButtonPressed, &tempInt); - *_retval = tempInt ? PR_FALSE : PR_TRUE; - - block->GetInt(eCheckboxState, & tempInt); - *checkValue = !!tempInt; - - return rv; -} - -NS_IMETHODIMP -nsPromptService::ConfirmEx(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - PRUint32 buttonFlags, const PRUnichar *button0Title, - const PRUnichar *button1Title, const PRUnichar *button2Title, - const PRUnichar *checkMsg, PRBool *checkValue, - PRInt32 *buttonPressed) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Return 1 to match what happens when the dialog is closed by the window - // manager (This is indeed independent of what the default button is). - // checkValue is an inout parameter, so we don't have to set it. - *buttonPressed = 1; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Confirm", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetString(eDialogTitle, dialogTitle); - block->SetString(eMsg, text); - - int buttonIDs[] = { eButton0Text, eButton1Text, eButton2Text }; - const PRUnichar* buttonStrings[] = { button0Title, button1Title, button2Title }; - -#define BUTTON_DEFAULT_MASK 0x03000000 - - block->SetInt(eDefaultButton, (buttonFlags & BUTTON_DEFAULT_MASK) >> 24); - block->SetInt(eDelayButtonEnable, buttonFlags & BUTTON_DELAY_ENABLE); - - PRInt32 numberButtons = 0; - for (int i = 0; i < 3; i++) { - - nsXPIDLString buttonTextStr; - const PRUnichar* buttonText = 0; - switch (buttonFlags & 0xff) { - case BUTTON_TITLE_OK: - GetLocaleString("OK", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_CANCEL: - GetLocaleString("Cancel", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_YES: - GetLocaleString("Yes", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_NO: - GetLocaleString("No", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_SAVE: - GetLocaleString("Save", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_DONT_SAVE: - GetLocaleString("DontSave", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_REVERT: - GetLocaleString("Revert", getter_Copies(buttonTextStr)); - break; - case BUTTON_TITLE_IS_STRING: - buttonText = buttonStrings[i]; - break; - } - if (!buttonText) - buttonText = buttonTextStr.get(); - - if (buttonText) { - block->SetString(buttonIDs[i], buttonText); - ++numberButtons; - } - buttonFlags >>= 8; - } - block->SetInt(eNumberButtons, numberButtons); - - block->SetString(eIconClass, NS_ConvertASCIItoUTF16(kQuestionIconClass).get()); - block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN); - - if (checkMsg && checkValue) { - block->SetString(eCheckboxMsg, checkMsg); - // since we're setting a PRInt32, we have to sanitize the PRBool first. - // (myBool != PR_FALSE) is guaranteed to return either 1 or 0. - block->SetInt(eCheckboxState, *checkValue != PR_FALSE); - } - - /* perform the dialog */ - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - /* get back output parameters */ - - if (buttonPressed) - block->GetInt(eButtonPressed, buttonPressed); - - if (checkMsg && checkValue) { - // GetInt returns a PRInt32; we need to sanitize it into PRBool - PRInt32 tempValue; - block->GetInt(eCheckboxState, &tempValue); - *checkValue = (tempValue == 1); - } - - return rv; -} - -NS_IMETHODIMP -nsPromptService::Prompt(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **value, - const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel. value and checkValue are inout parameters, so we - // don't have to set them. - *_retval = PR_FALSE; - return NS_OK; - } - - NS_ENSURE_ARG(value); - NS_ENSURE_ARG(_retval); - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Prompt", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt(eNumberButtons, 2); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetInt(eNumberEditfields, 1); - if (*value) - block->SetString(eEditfield1Value, *value); - if (checkMsg && checkValue) { - block->SetString(eCheckboxMsg, checkMsg); - block->SetInt(eCheckboxState, *checkValue); - } - block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 tempInt = 0; - block->GetInt(eButtonPressed, &tempInt); - *_retval = tempInt ? PR_FALSE : PR_TRUE; - - if (*_retval) { - PRUnichar *tempStr; - - rv = block->GetString(eEditfield1Value, &tempStr); - if (NS_FAILED(rv)) - return rv; - if (*value) - nsMemory::Free(*value); - *value = tempStr; - - if (checkValue) - block->GetInt(eCheckboxState, checkValue); - } - return rv; -} - -NS_IMETHODIMP -nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **username, PRUnichar **password, - const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval) - -{ - NS_ENSURE_ARG(username); - NS_ENSURE_ARG(password); - NS_ENSURE_ARG(_retval); - - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel - // username/password are inout, no need to set them - *_retval = PR_FALSE; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("PromptUsernameAndPassword2", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt(eNumberButtons, 2); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - NS_ConvertASCIItoUTF16 styleClass(kAuthenticationIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetInt( eNumberEditfields, 2 ); - if (*username) - block->SetString(eEditfield1Value, *username); - if (*password) - block->SetString(eEditfield2Value, *password); - if (checkMsg && checkValue) { - block->SetString(eCheckboxMsg, checkMsg); - block->SetInt(eCheckboxState, *checkValue); - } - block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 tempInt = 0; - block->GetInt(eButtonPressed, &tempInt); - *_retval = tempInt ? PR_FALSE : PR_TRUE; - - if (*_retval) { - PRUnichar *tempStr; - - rv = block->GetString(eEditfield1Value, &tempStr); - if (NS_FAILED(rv)) - return rv; - if (*username) - nsMemory::Free(*username); - *username = tempStr; - - rv = block->GetString(eEditfield2Value, &tempStr); - if (NS_FAILED(rv)) - return rv; - if (*password) - nsMemory::Free(*password); - *password = tempStr; - - if (checkValue) - block->GetInt(eCheckboxState, checkValue); - } - return rv; -} - -NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval) -{ - NS_ENSURE_ARG(password); - NS_ENSURE_ARG(_retval); - - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel. password and checkValue are inout parameters, so we - // don't have to touch them. - *_retval = PR_FALSE; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("PromptPassword2", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetInt(eNumberButtons, 2); - block->SetString(eMsg, text); - - block->SetString(eDialogTitle, dialogTitle); - - nsString url; - NS_ConvertASCIItoUTF16 styleClass(kAuthenticationIconClass); - block->SetString(eIconClass, styleClass.get()); - block->SetInt(eNumberEditfields, 1); - block->SetInt(eEditField1Password, 1); - if (*password) - block->SetString(eEditfield1Value, *password); - if (checkMsg && checkValue) { - block->SetString(eCheckboxMsg, checkMsg); - block->SetInt(eCheckboxState, *checkValue); - } - block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get()); - block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN); - - rv = DoDialog(parent, block, kPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 tempInt = 0; - block->GetInt(eButtonPressed, &tempInt); - *_retval = tempInt ? PR_FALSE : PR_TRUE; - if (*_retval) { - PRUnichar *tempStr; - - rv = block->GetString(eEditfield1Value, &tempStr); - if (NS_FAILED(rv)) - return rv; - if (*password) - nsMemory::Free(*password); - *password = tempStr; - - if (checkValue) - block->GetInt(eCheckboxState, checkValue); - } - return rv; -} - - -NS_IMETHODIMP -nsPromptService::PromptAuth(nsIDOMWindow* aParent, - nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - PRBool *retval) -{ - nsAutoWindowStateHelper windowStateHelper(aParent); - - if (!windowStateHelper.DefaultEnabled()) { - *retval = PR_FALSE; - return NS_OK; - } - - return nsPrompt::PromptPasswordAdapter(this, aParent, aChannel, - aLevel, aAuthInfo, - aCheckLabel, aCheckValue, - retval); -} - -NS_IMETHODIMP -nsPromptService::AsyncPromptAuth(nsIDOMWindow* aParent, - nsIChannel* aChannel, - nsIAuthPromptCallback* aCallback, - nsISupports* aContext, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - nsICancelable** retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle, - const PRUnichar* text, PRUint32 count, - const PRUnichar **selectList, PRInt32 *outSelection, - PRBool *_retval) -{ - nsAutoWindowStateHelper windowStateHelper(parent); - - if (!windowStateHelper.DefaultEnabled()) { - // Default to cancel and item 0 - *outSelection = 0; - *_retval = PR_FALSE; - return NS_OK; - } - - nsresult rv; - nsXPIDLString stringOwner; - - if (!dialogTitle) { - rv = GetLocaleString("Select", getter_Copies(stringOwner)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - dialogTitle = stringOwner.get(); - } - - const PRInt32 eSelection = 2; - ParamBlock block; - rv = block.Init(); - if (NS_FAILED(rv)) - return rv; - - block->SetNumberStrings(count + 2); - if (dialogTitle) - block->SetString(0, dialogTitle); - - block->SetString(1, text); - block->SetInt(eSelection, count); - for (PRUint32 i = 2; i <= count+1; i++) { - nsAutoString temp(selectList[i-2]); - const PRUnichar* text = temp.get(); - block->SetString(i, text); - } - - *outSelection = -1; - rv = DoDialog(parent, block, kSelectPromptURL); - if (NS_FAILED(rv)) - return rv; - - PRInt32 buttonPressed = 0; - block->GetInt(eButtonPressed, &buttonPressed); - block->GetInt(eSelection, outSelection); - *_retval = buttonPressed ? PR_FALSE : PR_TRUE; - - return rv; -} - -nsresult -nsPromptService::DoDialog(nsIDOMWindow *aParent, - nsIDialogParamBlock *aParamBlock, const char *aChromeURL) -{ - NS_ENSURE_ARG(aParamBlock); - NS_ENSURE_ARG(aChromeURL); - if (!mWatcher) - return NS_ERROR_FAILURE; - - nsresult rv = NS_OK; - - // get a parent, if at all possible - // (though we'd rather this didn't fail, it's OK if it does. so there's - // no failure or null check.) - nsCOMPtr activeParent; // retain ownership for method lifetime - if (!aParent) { - mWatcher->GetActiveWindow(getter_AddRefs(activeParent)); - aParent = activeParent; - } - - nsCOMPtr arguments(do_QueryInterface(aParamBlock)); - nsCOMPtr dialog; - rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank", - "centerscreen,chrome,modal,titlebar", arguments, - getter_AddRefs(dialog)); - - return rv; -} - -nsresult -nsPromptService::GetLocaleString(const char *aKey, PRUnichar **aResult) -{ - nsresult rv; - - nsCOMPtr stringService = do_GetService(NS_STRINGBUNDLE_CONTRACTID); - nsCOMPtr stringBundle; - - rv = stringService->CreateBundle(kCommonDialogsProperties, getter_AddRefs(stringBundle)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - rv = stringBundle->GetStringFromName(NS_ConvertASCIItoUTF16(aKey).get(), aResult); - - return rv; -} - diff --git a/embedding/components/windowwatcher/src/nsPromptService.h b/embedding/components/windowwatcher/src/nsPromptService.h deleted file mode 100644 index a9b7a6c5faa..00000000000 --- a/embedding/components/windowwatcher/src/nsPromptService.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsPromptService_h -#define __nsPromptService_h - -// {A2112D6A-0E28-421f-B46A-25C0B308CBD0} -#define NS_PROMPTSERVICE_CID \ - {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} -// {150E7415-72D7-11DA-A924-00039386357A} -#define NS_NONBLOCKINGALERTSERVICE_CID \ - {0x150e7415, 0x72d7, 0x11da, {0xa9, 0x24, 0x00, 0x03, 0x93, 0x86, 0x35, 0x7a}} - -#include "nsCOMPtr.h" -#include "nsIPromptService2.h" -#include "nsPIPromptService.h" -#include "nsIWindowWatcher.h" -#include "nsAutoWindowStateHelper.h" - -class nsIDOMWindow; -class nsIDialogParamBlock; - -class nsPromptService: public nsIPromptService2, - public nsPIPromptService { - -public: - - nsPromptService(); - virtual ~nsPromptService(); - - nsresult Init(); - - NS_DECL_NSIPROMPTSERVICE - NS_DECL_NSIPROMPTSERVICE2 - NS_DECL_NSPIPROMPTSERVICE - NS_DECL_ISUPPORTS - -private: - nsresult GetLocaleString(const char *aKey, PRUnichar **aResult); - - nsCOMPtr mWatcher; -}; - -#endif - diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index 1da64f1649a..a4c66c98a4a 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -40,12 +40,11 @@ //#define USEWEAKREFS // (haven't quite figured that out yet) #include "nsWindowWatcher.h" +#include "nsAutoWindowStateHelper.h" #include "nsAutoLock.h" #include "nsCRT.h" #include "nsNetUtil.h" -#include "nsPrompt.h" -#include "nsPromptService.h" #include "nsWWJSUtils.h" #include "plstr.h" #include "nsIContentUtils.h" @@ -62,6 +61,7 @@ #include "nsIDOMChromeWindow.h" #include "nsIDOMWindowInternal.h" #include "nsIDOMModalContentWindow.h" +#include "nsIPrompt.h" #include "nsIScriptObjectPrincipal.h" #include "nsIScreen.h" #include "nsIScreenManager.h" @@ -329,10 +329,9 @@ nsresult JSContextAutoPopper::Push(JSContext *cx) NS_IMPL_ADDREF(nsWindowWatcher) NS_IMPL_RELEASE(nsWindowWatcher) -NS_IMPL_QUERY_INTERFACE4(nsWindowWatcher, +NS_IMPL_QUERY_INTERFACE3(nsWindowWatcher, nsIWindowWatcher, nsIPromptFactory, - nsIAuthPromptAdapterFactory, nsPIWindowWatcher) nsWindowWatcher::nsWindowWatcher() : @@ -1065,54 +1064,46 @@ nsWindowWatcher::GetWindowEnumerator(nsISimpleEnumerator** _retval) NS_IMETHODIMP nsWindowWatcher::GetNewPrompter(nsIDOMWindow *aParent, nsIPrompt **_retval) { - return NS_NewPrompter(_retval, aParent); + // This is for backwards compat only. Callers should just use the prompt service directly. + nsresult rv; + nsCOMPtr factory = do_GetService("@mozilla.org/prompter;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + return factory->GetPrompt(aParent, NS_GET_IID(nsIPrompt), reinterpret_cast(_retval)); } NS_IMETHODIMP nsWindowWatcher::GetNewAuthPrompter(nsIDOMWindow *aParent, nsIAuthPrompt **_retval) { - return NS_NewAuthPrompter(_retval, aParent); + // This is for backwards compat only. Callers should just use the prompt service directly. + nsresult rv; + nsCOMPtr factory = do_GetService("@mozilla.org/prompter;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + return factory->GetPrompt(aParent, NS_GET_IID(nsIAuthPrompt), reinterpret_cast(_retval)); } NS_IMETHODIMP nsWindowWatcher::GetPrompt(nsIDOMWindow *aParent, const nsIID& aIID, void **_retval) { - if (aIID.Equals(NS_GET_IID(nsIPrompt))) - return NS_NewPrompter(reinterpret_cast(_retval), aParent); - if (aIID.Equals(NS_GET_IID(nsIAuthPrompt))) - return NS_NewAuthPrompter(reinterpret_cast(_retval), - aParent); - if (aIID.Equals(NS_GET_IID(nsIAuthPrompt2))) { - nsresult rv = NS_NewAuthPrompter2(reinterpret_cast - (_retval), - aParent); - if (rv == NS_NOINTERFACE) { - // Return an wrapped nsIAuthPrompt (if we can) - nsCOMPtr prompt; - rv = NS_NewAuthPrompter(getter_AddRefs(prompt), aParent); - if (NS_SUCCEEDED(rv)) { - NS_WrapAuthPrompt(prompt, - reinterpret_cast(_retval)); - if (!*_retval) - rv = NS_ERROR_NOT_AVAILABLE; - } - } + // This is for backwards compat only. Callers should just use the prompt service directly. + nsresult rv; + nsCOMPtr factory = do_GetService("@mozilla.org/prompter;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = factory->GetPrompt(aParent, aIID, _retval); - return rv; + // Allow for an embedding implementation to not support nsIAuthPrompt2. + if (rv == NS_NOINTERFACE && aIID.Equals(NS_GET_IID(nsIAuthPrompt2))) { + nsCOMPtr oldPrompt; + rv = factory->GetPrompt(aParent, + NS_GET_IID(nsIAuthPrompt), + getter_AddRefs(oldPrompt)); + NS_ENSURE_SUCCESS(rv, rv); + + NS_WrapAuthPrompt(oldPrompt, reinterpret_cast(_retval)); + if (!*_retval) + rv = NS_ERROR_NOT_AVAILABLE; } - - return NS_NOINTERFACE; -} - -NS_IMETHODIMP -nsWindowWatcher::CreateAdapter(nsIAuthPrompt* aPrompt, nsIAuthPrompt2** _retval) -{ - *_retval = new AuthPromptWrapper(aPrompt); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*_retval); - return NS_OK; + return rv; } NS_IMETHODIMP diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.h b/embedding/components/windowwatcher/src/nsWindowWatcher.h index 50eef22a237..92b7b3d8cf0 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.h +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.h @@ -47,7 +47,6 @@ #include "nsIWindowCreator.h" // for stupid compilers #include "nsIWindowWatcher.h" #include "nsIPromptFactory.h" -#include "nsIAuthPromptAdapterFactory.h" #include "nsPIWindowWatcher.h" #include "nsTArray.h" @@ -67,8 +66,7 @@ struct SizeSpec; class nsWindowWatcher : public nsIWindowWatcher, public nsPIWindowWatcher, - public nsIPromptFactory, - public nsIAuthPromptAdapterFactory + public nsIPromptFactory { friend class nsWatcherWindowEnumerator; @@ -83,7 +81,6 @@ public: NS_DECL_NSIWINDOWWATCHER NS_DECL_NSPIWINDOWWATCHER NS_DECL_NSIPROMPTFACTORY - NS_DECL_NSIAUTHPROMPTADAPTERFACTORY private: PRBool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator); diff --git a/netwerk/base/src/nsPACMan.cpp b/netwerk/base/src/nsPACMan.cpp index fdc7fccdf5e..0c61c1c79ed 100644 --- a/netwerk/base/src/nsPACMan.cpp +++ b/netwerk/base/src/nsPACMan.cpp @@ -42,6 +42,7 @@ #include "nsIDNSListener.h" #include "nsICancelable.h" #include "nsIAuthPrompt.h" +#include "nsIPromptFactory.h" #include "nsIHttpChannel.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" @@ -459,9 +460,11 @@ NS_IMETHODIMP nsPACMan::GetInterface(const nsIID &iid, void **result) { // In case loading the PAC file requires authentication. - if (iid.Equals(NS_GET_IID(nsIAuthPrompt))) - return CallCreateInstance(NS_DEFAULTAUTHPROMPT_CONTRACTID, - nsnull, iid, result); + if (iid.Equals(NS_GET_IID(nsIAuthPrompt))) { + nsCOMPtr promptFac = do_GetService("@mozilla.org/prompter;1"); + NS_ENSURE_TRUE(promptFac, NS_ERROR_FAILURE); + return promptFac->GetPrompt(nsnull, iid, reinterpret_cast(result)); + } // In case loading the PAC file results in a redirect. if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) { diff --git a/netwerk/build/nsNetCID.h b/netwerk/build/nsNetCID.h index 076301baf40..b6023cc4666 100644 --- a/netwerk/build/nsNetCID.h +++ b/netwerk/build/nsNetCID.h @@ -451,24 +451,6 @@ {0x82, 0xad, 0xa6, 0xa9, 0xbc, 0x5a, 0xd5, 0x99} \ } -// component implementing nsIPrompt -// -// NOTE: this implementation does not have any way to correctly parent itself, -// it is almost always wrong to get a prompt via this interface. -// use nsIWindowWatcher instead whenever possible. -// -#define NS_DEFAULTPROMPT_CONTRACTID \ - "@mozilla.org/network/default-prompt;1" - -// component implementing nsIAuthPrompt -// -// NOTE: this implementation does not have any way to correctly parent itself, -// it is almost always wrong to get an auth prompt via this interface. -// use nsIWindowWatcher instead whenever possible. -// -#define NS_DEFAULTAUTHPROMPT_CONTRACTID \ - "@mozilla.org/network/default-auth-prompt;1" - /** * Contract ID for a service implementing nsIURIClassifier that identifies * phishing and malware sites. diff --git a/netwerk/test/unit/test_authentication.js b/netwerk/test/unit/test_authentication.js index a63ddd6bfa6..159736a602e 100644 --- a/netwerk/test/unit/test_authentication.js +++ b/netwerk/test/unit/test_authentication.js @@ -37,7 +37,7 @@ AuthPrompt1.prototype = { function ap1_promptUP(title, text, realm, savePW, user, pw) { // Note that the realm here isn't actually the realm. it's a pw mgr key. - do_check_eq("localhost:4444 (" + this.expectedRealm + ")", realm); + do_check_eq("http://localhost:4444 (" + this.expectedRealm + ")", realm); if (text.indexOf(this.expectedRealm) == -1) do_throw("Text must indicate the realm"); if (text.indexOf("localhost") == -1) diff --git a/netwerk/test/unit/test_authpromptwrapper.js b/netwerk/test/unit/test_authpromptwrapper.js index 040348b87f1..c54104fd50f 100644 --- a/netwerk/test/unit/test_authpromptwrapper.js +++ b/netwerk/test/unit/test_authpromptwrapper.js @@ -78,10 +78,7 @@ function run_test() { }, doChecks: function ap1_check(text, realm) { - if (this.scheme == "http") - do_check_eq(host + ":80 (" + info.realm + ")", realm); - else - do_check_eq(this.scheme + "://" + host, realm); + do_check_eq(this.scheme + "://" + host + " (" + info.realm + ")", realm); do_check_neq(text.indexOf(host), -1); if (info.flags & nsIAuthInformation.ONLY_PASSWORD) { diff --git a/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js b/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js index 9b10a9ce97d..d97dcaf4b9c 100644 --- a/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js +++ b/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js @@ -48,8 +48,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); * * Implements nsIPromptFactory * - * Invoked by NS_NewAuthPrompter2() - * [embedding/components/windowwatcher/src/nsPrompt.cpp] + * Invoked by [toolkit/components/prompts/src/nsPrompter.js] */ function LoginManagerPromptFactory() { Services.obs.addObserver(this, "quit-application-granted", true); diff --git a/toolkit/content/commonDialog.css b/toolkit/components/prompts/content/commonDialog.css similarity index 97% rename from toolkit/content/commonDialog.css rename to toolkit/components/prompts/content/commonDialog.css index 635d2b092f2..f3c2c99ae71 100644 --- a/toolkit/content/commonDialog.css +++ b/toolkit/components/prompts/content/commonDialog.css @@ -48,7 +48,7 @@ white-space: pre-wrap; } -#loginLabel, #password1Label, #password2Label { +#loginLabel, #password1Label { text-align: right; } diff --git a/toolkit/components/prompts/content/commonDialog.js b/toolkit/components/prompts/content/commonDialog.js new file mode 100644 index 00000000000..334dec0052b --- /dev/null +++ b/toolkit/components/prompts/content/commonDialog.js @@ -0,0 +1,365 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alec Flett + * Ben Goodger + * Blake Ross + * Joe Hewitt + * Justin Dolske + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const Ci = Components.interfaces; +const Cr = Components.results; +const Cc = Components.classes; +const Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); + +let gArgs = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2) + .QueryInterface(Ci.nsIWritablePropertyBag); + +let promptType, numButtons, iconClass, soundID, hasInputField = true; + + +function earlyInit() { + // This is called before onload fires, so we can't be certain that any elements + // in the document have their bindings ready, so don't call any methods/properties + // here on xul elements that come from xbl bindings. + + promptType = gArgs.getProperty("promptType"); + + switch (promptType) { + case "alert": + case "alertCheck": + hasInputField = false; + numButtons = 1; + iconClass = "alert-icon"; + soundID = Ci.nsISound.EVENT_ALERT_DIALOG_OPEN; + break; + case "confirmCheck": + case "confirm": + hasInputField = false; + numButtons = 2; + iconClass = "question-icon"; + soundID = Ci.nsISound.EVENT_CONFIRM_DIALOG_OPEN; + break; + case "confirmEx": + numButtons = 0; + if (gArgs.hasKey("button0Label")) + numButtons++; + if (gArgs.hasKey("button1Label")) + numButtons++; + if (gArgs.hasKey("button2Label")) + numButtons++; + if (gArgs.hasKey("button3Label")) + numButtons++; + if (numButtons == 0) + throw "A dialog with no buttons? Can not haz."; + hasInputField = false; + iconClass = "question-icon"; + soundID = Ci.nsISound.EVENT_CONFIRM_DIALOG_OPEN; + break; + case "prompt": + numButtons = 2; + iconClass = "question-icon"; + soundID = Ci.nsISound.EVENT_PROMPT_DIALOG_OPEN; + initTextbox("login", gArgs.getProperty("value")); + // Clear the label, since this isn't really a username prompt. + document.getElementById("loginLabel").setAttribute("value", ""); + break; + case "promptUserAndPass": + numButtons = 2; + iconClass = "authentication-icon question-icon"; + soundID = Ci.nsISound.EVENT_PROMPT_DIALOG_OPEN; + initTextbox("login", gArgs.getProperty("user")); + initTextbox("password1", gArgs.getProperty("pass")); + break; + case "promptPassword": + numButtons = 2; + iconClass = "authentication-icon question-icon"; + soundID = Ci.nsISound.EVENT_PROMPT_DIALOG_OPEN; + initTextbox("password1", gArgs.getProperty("pass")); + break; + default: + Cu.reportError("commonDialog opened for unknown type: " + promptType); + window.close(); + } +} + +function initTextbox(aName, aValue) { + document.getElementById(aName + "Container").hidden = false; + document.getElementById(aName + "Textbox").setAttribute("value", aValue); +} + +function setLabelForNode(aNode, aLabel, aIsLabelFlag) { + // This is for labels which may contain embedded access keys. + // If we end in (&X) where X represents the access key, optionally preceded + // by spaces and/or followed by the ':' character, store the access key and + // remove the access key placeholder + leading spaces from the label. + // Otherwise a character preceded by one but not two &s is the access key. + // Store it and remove the &. + + // Note that if you change the following code, see the comment of + // nsTextBoxFrame::UpdateAccessTitle. + var accessKey = null; + if (/ *\(\&([^&])\)(:)?$/.test(aLabel)) { + aLabel = RegExp.leftContext + RegExp.$2; + accessKey = RegExp.$1; + } else if (/^(.*[^&])?\&(([^&]).*$)/.test(aLabel)) { + aLabel = RegExp.$1 + RegExp.$2; + accessKey = RegExp.$3; + } + + // && is the magic sequence to embed an & in your label. + aLabel = aLabel.replace(/\&\&/g, "&"); + if (aIsLabelFlag) { // Set text for