new embedding promptservice component. bug 72112 r=hyatt,pinkerton

git-svn-id: svn://10.0.0.236/trunk@91503 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
danm%netscape.com
2001-04-05 23:09:35 +00:00
parent 837b67f9ec
commit 478efe7481
19 changed files with 853 additions and 2 deletions

View File

@@ -745,6 +745,9 @@ embedding/browser/photon/src/Makefile
embedding/browser/photon/tests/Makefile
embedding/components/Makefile
embedding/components/build/Makefile
embedding/components/promptservice/Makefile
embedding/components/promptservice/public/Makefile
embedding/components/promptservice/src/Makefile
embedding/components/windowwatcher/Makefile
embedding/components/windowwatcher/public/Makefile
embedding/components/windowwatcher/src/Makefile

View File

@@ -719,6 +719,7 @@ sub BuildClientDist()
#EMBEDDING
InstallFromManifest(":mozilla:embedding:base:MANIFEST_IDL", "$distdirectory:idl:");
InstallFromManifest(":mozilla:embedding:browser:webbrowser:MANIFEST_IDL", "$distdirectory:idl:");
InstallFromManifest(":mozilla:embedding:components:promptservice:public:MANIFEST_IDL", "$distdirectory:idl:");
InstallFromManifest(":mozilla:embedding:components:windowwatcher:public:MANIFEST_IDL", "$distdirectory:idl:");
InstallFromManifest(":mozilla:embedding:components:appstartup:src:MANIFEST", "$distdirectory:embedding:components:");

View File

@@ -24,6 +24,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = windowwatcher appstartup build
DIRS = promptservice windowwatcher appstartup build
include $(topsrcdir)/config/rules.mk

View File

@@ -27,12 +27,13 @@ MODULE = embedcomponents
LIBRARY_NAME = embedcomponents
SHORT_LIBNAME = embedcmp
IS_COMPONENT = 1
REQUIRES = js xpcom string windowwatcher embed_base
REQUIRES = js xpcom string promptservice windowwatcher embed_base
CPPSRCS = nsModule.cpp
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
EXTRA_DSO_LIBS = \
promptservice_s \
windowwatcher_s \
appstartupnotifier_s \
$(NULL)
@@ -45,6 +46,7 @@ endif
else
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libpromptservice_s.$(LIB_SUFFIX) \
$(DIST)/lib/libwindowwatcher_s.$(LIB_SUFFIX) \
$(DIST)/lib/libappstartupnotifier_s.$(LIB_SUFFIX) \
$(NULL)
@@ -56,6 +58,7 @@ endif
endif
LOCAL_INCLUDES = \
-I$(srcdir)/../promptservice/src \
-I$(srcdir)/../windowwatcher/src \
-I$(srcdir)/../appstartup/src \
$(NULL)

View File

@@ -35,11 +35,13 @@ LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\promptservice_s.lib \
$(DIST)\lib\windowwatcher_s.lib \
$(DIST)\lib\appstartupnotifier_s.lib \
$(NULL)
INCS = $(INCS) \
-I$(DEPTH)\embedding\components\promptservice\src \
-I$(DEPTH)\embedding\components\windowwatcher\src \
-I$(DEPTH)\embedding\components\appstartup\src \
$(NULL)

View File

@@ -21,14 +21,17 @@
*/
#include "nsIGenericFactory.h"
#include "nsPromptService.h"
#include "nsWindowWatcher.h"
#include "nsAppStartupNotifier.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPromptService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWindowWatcher, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppStartupNotifier)
static nsModuleComponentInfo components[] = {
{ "Prompt Service", NS_PROMPTSERVICE_CID, NS_PROMPTSERVICE_CONTRACTID, nsPromptServiceConstructor },
{ "Window Watcher", NS_WINDOWWATCHER_CID, NS_WINDOWWATCHER_CONTRACTID, nsWindowWatcherConstructor },
{ NS_APPSTARTUPNOTIFIER_CLASSNAME, NS_APPSTARTUPNOTIFIER_CID, NS_APPSTARTUPNOTIFIER_CONTRACTID, nsAppStartupNotifierConstructor }
};

View File

@@ -21,6 +21,7 @@
DEPTH=..\..
DIRS= \
promptservice \
windowwatcher \
appstartup \
build \

View File

@@ -0,0 +1,29 @@
#
# 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, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,25 @@
#!nmake
#
# 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, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..
DIRS=public src
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1 @@
nsIPromptService.idl

View File

@@ -0,0 +1,36 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = promptservice
XPIDL_MODULE = promptservice
XPIDLSRCS = nsIPromptService.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,30 @@
#!nmake
#
# 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, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
MODULE=promptservice
XPIDLSRCS = \
.\nsIPromptService.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,125 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* This is the interface to the embeddable prompt service; the service
that implements nsIPrompt. Its interface is designed to be just
nsIPrompt, each method modified to take a parent window parameter.
See nsIPrompt for all documentation and ancillary documentation.
One note: in all cases, the parent window parameter can be null.
However, these windows are all intended to have parents. So when
no parent is specified, the implementation should try hard to find
a suitable foster parent. */
#include "nsISupports.idl"
interface nsIDOMWindow;
[scriptable, uuid(1630C61A-325E-49ca-8759-A31B16C47AA5)]
interface nsIPromptService : nsISupports
{
%{C++
enum {eMsg=0, eCheckboxMsg=1, eIconURL=2, eTitleMessage=3, eEditfield1Msg=4,
eEditfield2Msg=5, eEditfield1Value=6, eEditfield2Value=7,
eButton0Text=8, eButton1Text=9, eButton2Text=10, eButton3Text=11,
eDialogTitle=12};
enum {eButtonPressed=0, eCheckboxState=1, eNumberButtons=2,
eNumberEditfields=3, eEditField1Password=4};
%}
void alert(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text);
void alertCheck(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in wstring checkMsg,
out boolean checkValue);
boolean confirm(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text);
boolean confirmCheck(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in wstring checkMsg,
out boolean checkValue);
boolean prompt(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in wstring passwordRealm,
in PRUint32 savePassword,
in wstring defaultText,
out wstring result);
boolean promptUsernameAndPassword(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in wstring passwordRealm,
in PRUint32 savePassword,
out wstring user,
out wstring pwd);
boolean promptPassword(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in wstring passwordRealm,
in PRUint32 savePassword,
out wstring pwd);
boolean select(in nsIDOMWindow parent,
in wstring dialogTitle,
in wstring text,
in PRUint32 count,
[array, size_is(count)] in wstring selectList,
out long outSelection);
void universalDialog(in nsIDOMWindow parent,
in wstring titleMessage,
in wstring dialogTitle,
in wstring text,
in wstring checkboxMsg,
in wstring button0Text,
in wstring button1Text,
in wstring button2Text,
in wstring button3Text,
in wstring editfield1Msg,
in wstring editfield2Msg,
inout wstring editfield1Value,
inout wstring editfield2Value,
in wstring iconURL,
inout boolean checkboxState,
in PRInt32 numberButtons,
in PRInt32 numberEditfields,
in PRInt32 editField1Password,
out PRInt32 buttonPressed);
};
%{C++
// {1630C61A-325E-49ca-8759-A31B16C47AA5}
#define NS_PROMPTSERVICE_IID \
{0x1630C61A, 0x325E, 0x49ca, {0x87, 0x59, 0xA3, 0x1B, 0x16, 0xC4, 0x7A, 0xA5}}
%}

View File

@@ -0,0 +1,40 @@
#
# 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, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = embedcomponents
LIBRARY_NAME = promptservice_s
REQUIRES = xpcom string dom promptservice widget js xpconnect caps layout uriloader necko docshell locale webbrwsr embed_base gfx2
CPPSRCS = nsPromptService.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,36 @@
#!nmake
#
# 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, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
MODULE=embedcomponents
LIBRARY_NAME=promptservice_s
CPP_OBJS= \
.\$(OBJDIR)\nsPromptService.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,455 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsPromptService.h"
#include "nsXPComFactory.h"
#include "nsIComponentManager.h"
#include "nsIDialogParamBlock.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsISupportsUtils.h"
static NS_DEFINE_CID(kDialogParamBlockCID, NS_DialogParamBlock_CID);
const char *kPromptURL="chrome://global/content/commonDialog.xul";
const char *kSelectPromptURL="chrome://global/content/selectDialog.xul";
const char *kQuestionIconURL ="chrome://global/skin/question-icon.gif";
const char *kAlertIconURL ="chrome://global/skin/alert-icon.gif";
const char *kWarningIconURL ="chrome://global/skin/message-icon.gif";
/****************************************************************
************************* ParamBlock ***************************
****************************************************************/
class ParamBlock {
public:
ParamBlock() {
mBlock = 0;
}
~ParamBlock() {
NS_IF_RELEASE(mBlock);
}
nsresult Init() {
return nsComponentManager::CreateInstance(kDialogParamBlockCID,
0, NS_GET_IID(nsIDialogParamBlock),
(void**) &mBlock);
}
nsIDialogParamBlock * operator->() const { return mBlock; }
operator nsIDialogParamBlock * const () { return mBlock; }
private:
nsIDialogParamBlock *mBlock;
};
/****************************************************************
************************ nsPromptService ***********************
****************************************************************/
NS_IMPL_ISUPPORTS1(nsPromptService, nsIPromptService)
nsPromptService::nsPromptService() {
NS_INIT_REFCNT();
}
nsPromptService::~nsPromptService() {
}
nsresult
nsPromptService::Init()
{
nsresult rv;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
return rv;
}
NS_IMETHODIMP
nsPromptService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle, const PRUnichar *text)
{
nsresult rv;
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;
url.AssignWithConversion(kAlertIconURL);
block->SetString(eIconURL, url.GetUnicode());
rv = DoDialog(parent, block, kPromptURL);
return rv;
}
NS_IMETHODIMP
nsPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle, const PRUnichar *text,
const PRUnichar *checkMsg, PRBool *checkValue)
{
nsresult rv;
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;
url.AssignWithConversion(kAlertIconURL);
block->SetString(eIconURL, url.GetUnicode());
block->SetString(eCheckboxMsg, checkMsg);
block->SetInt(eCheckboxState, *checkValue);
rv = DoDialog(parent, block, kPromptURL);
block->GetInt(eCheckboxState, checkValue);
return rv;
}
NS_IMETHODIMP
nsPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle, const PRUnichar *text,
PRBool *_retval)
{
nsresult rv;
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);
nsString url;
url.AssignWithConversion(kQuestionIconURL);
block->SetString(eIconURL, url.GetUnicode());
rv = DoDialog(parent, block, kPromptURL);
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)
{
nsresult rv;
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; url.AssignWithConversion( kQuestionIconURL );
block->SetString(eIconURL, url.GetUnicode());
block->SetString(eCheckboxMsg, checkMsg);
block->SetInt(eCheckboxState, *checkValue);
rv = DoDialog(parent, block, kPromptURL);
PRInt32 tempInt = 0;
block->GetInt(eButtonPressed, &tempInt);
*_retval = tempInt ? PR_FALSE : PR_TRUE;
block->GetInt(eCheckboxState, & tempInt);
*checkValue = PRBool( tempInt );
return rv;
}
NS_IMETHODIMP
nsPromptService::UniversalDialog(nsIDOMWindow *parent,
const PRUnichar *titleMessage, const PRUnichar *dialogTitle,
const PRUnichar *text, const PRUnichar *checkboxMsg,
const PRUnichar *button0Text, const PRUnichar *button1Text,
const PRUnichar *button2Text, const PRUnichar *button3Text,
const PRUnichar *editfield1Msg, const PRUnichar *editfield2Msg,
PRUnichar **editfield1Value, PRUnichar **editfield2Value,
const PRUnichar *iconURL, PRBool *checkboxState,
PRInt32 numberButtons, PRInt32 numberEditfields,
PRInt32 editfield1Password, PRInt32 *buttonPressed)
{
nsresult rv;
/* check for at least one button */
if (numberButtons < 1)
rv = NS_ERROR_FAILURE;
ParamBlock block;
rv = block.Init();
if (NS_FAILED(rv))
return rv;
/* load up input parameters */
block->SetString(eTitleMessage, titleMessage);
block->SetString(eDialogTitle, dialogTitle);
block->SetString(eMsg, text);
block->SetString(eCheckboxMsg, checkboxMsg);
if (numberButtons >= 4)
block->SetString(eButton3Text, button3Text);
if (numberButtons >= 3)
block->SetString(eButton2Text, button2Text);
if (numberButtons >= 2)
block->SetString(eButton1Text, button1Text);
if (numberButtons >= 1)
block->SetString(eButton0Text, button0Text);
if (numberEditfields >= 2) {
block->SetString(eEditfield2Msg, editfield2Msg);
block->SetString(eEditfield2Value, *editfield2Value);
}
if (numberEditfields >= 1) {
block->SetString(eEditfield1Msg, editfield1Msg);
block->SetString(eEditfield1Value, *editfield1Value);
block->SetInt(eEditField1Password, editfield1Password);
}
if (iconURL)
block->SetString(eIconURL, iconURL);
else
block->SetString(eIconURL, NS_ConvertASCIItoUCS2(kQuestionIconURL).GetUnicode());
if (checkboxMsg)
block->SetInt(eCheckboxState, *checkboxState);
block->SetInt(eNumberButtons, numberButtons);
block->SetInt(eNumberEditfields, numberEditfields);
/* perform the dialog */
rv = DoDialog(parent, block, kPromptURL);
/* get back output parameters */
if (buttonPressed)
block->GetInt(eButtonPressed, buttonPressed);
if (checkboxMsg && checkboxState)
block->GetInt(eCheckboxState, checkboxState);
if (numberEditfields >= 2 && editfield2Value)
block->GetString(eEditfield2Value, editfield2Value);
if (numberEditfields >= 1 && editfield1Value)
block->GetString(eEditfield1Value, editfield1Value);
return rv;
}
// XXX use passwordRealm and savePassword, here and in
// PromptUsernameAndPassword and PromptPassword
NS_IMETHODIMP
nsPromptService::Prompt(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text, const PRUnichar *passwordRealm,
PRUint32 savePassword, const PRUnichar *defaultText,
PRUnichar **result, PRBool *_retval)
{
nsresult rv;
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; url.AssignWithConversion(kQuestionIconURL);
block->SetString(eIconURL, url.GetUnicode());
block->SetInt(eNumberEditfields, 1);
block->SetString(eEditfield1Value, defaultText);
rv = DoDialog(parent, block, kPromptURL);
block->GetString(eEditfield1Value, result);
PRInt32 tempInt = 0;
block->GetInt(eButtonPressed, &tempInt);
*_retval = tempInt ? PR_FALSE : PR_TRUE;
return rv;
}
NS_IMETHODIMP
nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle, const PRUnichar *text,
const PRUnichar *passwordRealm, PRUint32 savePassword,
PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
{
nsresult rv;
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;
url.AssignWithConversion(kQuestionIconURL);
block->SetString(eIconURL, url.GetUnicode());
block->SetInt( eNumberEditfields, 2 );
block->SetString(eEditfield1Value, *user);
block->SetString(eEditfield2Value, *pwd);
rv = DoDialog(parent, block, kPromptURL);
block->GetString(eEditfield1Value, user);
block->GetString(eEditfield2Value, pwd);
PRInt32 tempInt = 0;
block->GetInt(eButtonPressed, &tempInt);
*_retval = tempInt ? PR_FALSE : PR_TRUE;
return rv;
}
NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle, const PRUnichar *text,
const PRUnichar *passwordRealm, PRUint32 savePassword,
PRUnichar **pwd, PRBool *_retval)
{
nsresult rv;
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;
url.AssignWithConversion(kQuestionIconURL);
block->SetString(eIconURL, url.GetUnicode());
block->SetInt(eNumberEditfields, 1);
block->SetInt(eEditField1Password, 1);
rv = DoDialog(parent, block, kPromptURL);
block->GetString(eEditfield1Value, pwd);
PRInt32 tempInt = 0;
block->GetInt(eButtonPressed, &tempInt);
*_retval = tempInt ? PR_FALSE : PR_TRUE;
return rv;
}
NS_IMETHODIMP
nsPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar* text, PRUint32 count,
const PRUnichar **selectList, PRInt32 *outSelection,
PRBool *_retval)
{
nsresult rv;
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.GetUnicode();
block->SetString(i, text);
}
*outSelection = -1;
rv = DoDialog(parent, block, kSelectPromptURL);
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<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent) {
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
nsCOMPtr<nsISupports> arguments(do_QueryInterface(aParamBlock));
nsCOMPtr<nsIDOMWindow> dialog;
mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
return rv;
}

View File

@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#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}}
#define NS_PROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/prompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPromptService.h"
#include "nsIWindowWatcher.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPromptService: public nsIPromptService {
public:
nsPromptService();
virtual ~nsPromptService();
nsresult Init();
NS_DECL_NSIPROMPTSERVICE
NS_DECL_ISUPPORTS
private:
nsresult DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
const char *aChromeURL);
nsCOMPtr<nsIWindowWatcher> mWatcher;
};
#endif