Back to index

lightning-sunbird  0.9+nobinonly
nsPromptService.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsPromptService.h"
00039 
00040 #include "nsDialogParamBlock.h"
00041 #include "nsIComponentManager.h"
00042 #include "nsIDialogParamBlock.h"
00043 #include "nsIDOMWindow.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsISupportsUtils.h"
00046 #include "nsString.h"
00047 #include "nsIStringBundle.h"
00048 #include "nsXPIDLString.h"
00049 
00050 static const char kPromptURL[] = "chrome://global/content/commonDialog.xul";
00051 static const char kSelectPromptURL[] = "chrome://global/content/selectDialog.xul";
00052 static const char kQuestionIconClass[] = "question-icon";
00053 static const char kAlertIconClass[] = "alert-icon";
00054 static const char kWarningIconClass[] = "message-icon";
00055 
00056 static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
00057 
00058 #define kCommonDialogsProperties "chrome://global/locale/commonDialogs.properties"
00059 
00060 
00061 /****************************************************************
00062  ************************* ParamBlock ***************************
00063  ****************************************************************/
00064 
00065 class ParamBlock {
00066 
00067 public:
00068   ParamBlock() {
00069     mBlock = 0;
00070   }
00071   ~ParamBlock() {
00072     NS_IF_RELEASE(mBlock);
00073   }
00074   nsresult Init() {
00075     return CallCreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &mBlock);
00076   }
00077   nsIDialogParamBlock * operator->() const { return mBlock; }
00078   operator nsIDialogParamBlock * const () { return mBlock; }
00079 
00080 private:
00081   nsIDialogParamBlock *mBlock;
00082 };
00083 
00084 /****************************************************************
00085  ************************ nsPromptService ***********************
00086  ****************************************************************/
00087 
00088 NS_IMPL_ISUPPORTS3(nsPromptService, nsIPromptService,
00089                    nsPIPromptService, nsINonBlockingAlertService)
00090 
00091 nsPromptService::nsPromptService() {
00092 }
00093 
00094 nsPromptService::~nsPromptService() {
00095 }
00096 
00097 nsresult
00098 nsPromptService::Init()
00099 {
00100   nsresult rv;
00101   mWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
00102   return rv;
00103 }
00104 
00105 NS_IMETHODIMP
00106 nsPromptService::Alert(nsIDOMWindow *parent,
00107                    const PRUnichar *dialogTitle, const PRUnichar *text)
00108 {
00109   nsresult rv;
00110   nsXPIDLString stringOwner;
00111  
00112   if (!dialogTitle) {
00113     rv = GetLocaleString("Alert", getter_Copies(stringOwner));
00114     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00115     dialogTitle = stringOwner.get();
00116   }
00117 
00118   ParamBlock block;
00119   rv = block.Init();
00120   if (NS_FAILED(rv))
00121     return rv;
00122 
00123   block->SetInt(eNumberButtons, 1);
00124   block->SetString(eMsg, text);
00125 
00126   block->SetString(eDialogTitle, dialogTitle);
00127 
00128   nsString url;
00129   NS_ConvertASCIItoUCS2 styleClass(kAlertIconClass);
00130   block->SetString(eIconClass, styleClass.get());
00131 
00132   rv = DoDialog(parent, block, kPromptURL);
00133 
00134   return rv;
00135 }
00136 
00137 
00138 
00139 NS_IMETHODIMP
00140 nsPromptService::AlertCheck(nsIDOMWindow *parent,
00141                             const PRUnichar *dialogTitle, const PRUnichar *text,
00142                             const PRUnichar *checkMsg, PRBool *checkValue)
00143 
00144 {
00145   nsresult rv;
00146   nsXPIDLString stringOwner;
00147  
00148   if (!dialogTitle) {
00149     rv = GetLocaleString("Alert", getter_Copies(stringOwner));
00150     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00151     dialogTitle = stringOwner.get();
00152   }
00153 
00154   ParamBlock block;
00155   rv = block.Init();
00156   if (NS_FAILED(rv))
00157     return rv;
00158 
00159   block->SetInt( eNumberButtons,1 );
00160   block->SetString(eMsg, text);
00161 
00162   block->SetString(eDialogTitle, dialogTitle);
00163 
00164   NS_ConvertASCIItoUCS2 styleClass(kAlertIconClass);
00165   block->SetString(eIconClass, styleClass.get());
00166   block->SetString(eCheckboxMsg, checkMsg);
00167   block->SetInt(eCheckboxState, *checkValue);
00168 
00169   rv = DoDialog(parent, block, kPromptURL);
00170   if (NS_FAILED(rv))
00171     return rv;
00172 
00173   block->GetInt(eCheckboxState, checkValue);
00174 
00175   return rv;
00176 }
00177 
00178 NS_IMETHODIMP
00179 nsPromptService::Confirm(nsIDOMWindow *parent,
00180                    const PRUnichar *dialogTitle, const PRUnichar *text,
00181                    PRBool *_retval)
00182 {
00183   nsresult rv;
00184   nsXPIDLString stringOwner;
00185  
00186   if (!dialogTitle) {
00187     rv = GetLocaleString("Confirm", getter_Copies(stringOwner));
00188     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00189     dialogTitle = stringOwner.get();
00190   }
00191 
00192   ParamBlock block;
00193   rv = block.Init();
00194   if (NS_FAILED(rv))
00195     return rv;
00196 
00197   // Stuff in Parameters
00198   block->SetInt(eNumberButtons, 2);
00199   block->SetString(eMsg, text);
00200   
00201   block->SetString(eDialogTitle, dialogTitle);
00202 
00203   NS_ConvertASCIItoUCS2 styleClass(kQuestionIconClass);
00204   block->SetString(eIconClass, styleClass.get());
00205   
00206   rv = DoDialog(parent, block, kPromptURL);
00207   if (NS_FAILED(rv))
00208     return rv;
00209   
00210   PRInt32 buttonPressed = 0;
00211   block->GetInt(eButtonPressed, &buttonPressed);
00212   *_retval = buttonPressed ? PR_FALSE : PR_TRUE;
00213 
00214   return rv;
00215 }
00216 
00217 NS_IMETHODIMP
00218 nsPromptService::ConfirmCheck(nsIDOMWindow *parent,
00219                    const PRUnichar *dialogTitle, const PRUnichar *text,
00220                    const PRUnichar *checkMsg, PRBool *checkValue,
00221                    PRBool *_retval)
00222 {
00223   nsresult rv;
00224   nsXPIDLString stringOwner;
00225  
00226   if (!dialogTitle) {
00227     rv = GetLocaleString("ConfirmCheck", getter_Copies(stringOwner));
00228     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00229     dialogTitle = stringOwner.get();
00230   }
00231 
00232   ParamBlock block;
00233   rv = block.Init();
00234   if (NS_FAILED(rv))
00235     return rv;
00236 
00237   block->SetInt( eNumberButtons,2 );
00238   block->SetString(eMsg, text);
00239 
00240   block->SetString(eDialogTitle, dialogTitle);
00241 
00242   NS_ConvertASCIItoUCS2 styleClass(kQuestionIconClass);
00243   block->SetString(eIconClass, styleClass.get());
00244   block->SetString(eCheckboxMsg, checkMsg);
00245   block->SetInt(eCheckboxState, *checkValue);
00246 
00247   rv = DoDialog(parent, block, kPromptURL);
00248   if (NS_FAILED(rv))
00249     return rv;
00250 
00251   PRInt32 tempInt = 0;
00252   block->GetInt(eButtonPressed, &tempInt);
00253   *_retval = tempInt ? PR_FALSE : PR_TRUE;
00254 
00255   block->GetInt(eCheckboxState, & tempInt);
00256   *checkValue = PRBool( tempInt );
00257   
00258   return rv;
00259 }
00260 
00261 NS_IMETHODIMP
00262 nsPromptService::ConfirmEx(nsIDOMWindow *parent,
00263                     const PRUnichar *dialogTitle, const PRUnichar *text,
00264                     PRUint32 buttonFlags, const PRUnichar *button0Title,
00265                     const PRUnichar *button1Title, const PRUnichar *button2Title,
00266                     const PRUnichar *checkMsg, PRBool *checkValue,
00267                     PRInt32 *buttonPressed)
00268 {
00269   nsresult rv;
00270   nsXPIDLString stringOwner;
00271  
00272   if (!dialogTitle) {
00273     rv = GetLocaleString("Confirm", getter_Copies(stringOwner));
00274     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00275     dialogTitle = stringOwner.get();
00276   }
00277 
00278   ParamBlock block;
00279   rv = block.Init();
00280   if (NS_FAILED(rv))
00281     return rv;
00282 
00283   block->SetString(eDialogTitle, dialogTitle);
00284   block->SetString(eMsg, text);
00285   
00286   int buttonIDs[] = { eButton0Text, eButton1Text, eButton2Text };
00287   const PRUnichar* buttonStrings[] = { button0Title, button1Title, button2Title };
00288 
00289 #define BUTTON_DEFAULT_MASK 0x03000000
00290 
00291   block->SetInt(eDefaultButton, (buttonFlags & BUTTON_DEFAULT_MASK) >> 24);
00292   block->SetInt(eDelayButtonEnable, buttonFlags & BUTTON_DELAY_ENABLE);
00293  
00294   PRInt32 numberButtons = 0;
00295   for (int i = 0; i < 3; i++) { 
00296     
00297     nsXPIDLString buttonTextStr;
00298     const PRUnichar* buttonText = 0;
00299     switch (buttonFlags & 0xff) {
00300       case BUTTON_TITLE_OK:
00301         GetLocaleString("OK", getter_Copies(buttonTextStr));
00302         break;
00303       case BUTTON_TITLE_CANCEL:
00304         GetLocaleString("Cancel", getter_Copies(buttonTextStr));
00305         break;
00306       case BUTTON_TITLE_YES:
00307         GetLocaleString("Yes", getter_Copies(buttonTextStr));
00308         break;
00309       case BUTTON_TITLE_NO:
00310         GetLocaleString("No", getter_Copies(buttonTextStr));
00311         break;
00312       case BUTTON_TITLE_SAVE:
00313         GetLocaleString("Save", getter_Copies(buttonTextStr));
00314         break;
00315       case BUTTON_TITLE_DONT_SAVE:
00316         GetLocaleString("DontSave", getter_Copies(buttonTextStr));
00317         break;
00318       case BUTTON_TITLE_REVERT:
00319         GetLocaleString("Revert", getter_Copies(buttonTextStr));
00320         break;
00321       case BUTTON_TITLE_IS_STRING:
00322         buttonText = buttonStrings[i];
00323         break;
00324     }
00325     if (!buttonText)
00326       buttonText = buttonTextStr.get();
00327 
00328     if (buttonText) {
00329       block->SetString(buttonIDs[i], buttonText);
00330       ++numberButtons;
00331     }
00332     buttonFlags >>= 8;
00333   }
00334   block->SetInt(eNumberButtons, numberButtons);
00335   
00336   block->SetString(eIconClass, NS_ConvertASCIItoUCS2(kQuestionIconClass).get());
00337 
00338   if (checkMsg && checkValue) {
00339     block->SetString(eCheckboxMsg, checkMsg);
00340     // since we're setting a PRInt32, we have to sanitize the PRBool first.
00341     // (myBool != PR_FALSE) is guaranteed to return either 1 or 0.
00342     block->SetInt(eCheckboxState, *checkValue != PR_FALSE);
00343   }
00344   
00345   /* perform the dialog */
00346 
00347   rv = DoDialog(parent, block, kPromptURL);
00348   if (NS_FAILED(rv))
00349     return rv;
00350 
00351   /* get back output parameters */
00352 
00353   if (buttonPressed)
00354     block->GetInt(eButtonPressed, buttonPressed);
00355 
00356   if (checkMsg && checkValue) {
00357     // GetInt returns a PRInt32; we need to sanitize it into PRBool
00358     PRInt32 tempValue;
00359     block->GetInt(eCheckboxState, &tempValue);
00360     *checkValue = (tempValue == 1);
00361   }
00362 
00363   return rv;
00364 }
00365 
00366 NS_IMETHODIMP
00367 nsPromptService::Prompt(nsIDOMWindow *parent,
00368                         const PRUnichar *dialogTitle, const PRUnichar *text,
00369                         PRUnichar **value,
00370                         const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
00371 {
00372   NS_ENSURE_ARG(value);
00373   NS_ENSURE_ARG(_retval);
00374 
00375   nsresult rv;
00376   nsXPIDLString stringOwner;
00377  
00378   if (!dialogTitle) {
00379     rv = GetLocaleString("Prompt", getter_Copies(stringOwner));
00380     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00381     dialogTitle = stringOwner.get();
00382   }
00383 
00384   ParamBlock block;
00385   rv = block.Init();
00386   if (NS_FAILED(rv))
00387     return rv;
00388 
00389   block->SetInt(eNumberButtons, 2);
00390   block->SetString(eMsg, text);
00391 
00392   block->SetString(eDialogTitle, dialogTitle);
00393 
00394   NS_ConvertASCIItoUCS2 styleClass(kQuestionIconClass);
00395   block->SetString(eIconClass, styleClass.get());
00396   block->SetInt(eNumberEditfields, 1);
00397   if (*value)
00398     block->SetString(eEditfield1Value, *value);
00399   if (checkMsg && checkValue) {
00400     block->SetString(eCheckboxMsg, checkMsg);
00401     block->SetInt(eCheckboxState, *checkValue);
00402   }
00403 
00404   rv = DoDialog(parent, block, kPromptURL);
00405   if (NS_FAILED(rv))
00406     return rv;
00407 
00408   PRInt32 tempInt = 0;
00409   block->GetInt(eButtonPressed, &tempInt);
00410   *_retval = tempInt ? PR_FALSE : PR_TRUE;
00411 
00412   if (*_retval) {
00413     PRUnichar *tempStr;
00414     
00415     rv = block->GetString(eEditfield1Value, &tempStr);
00416     if (NS_FAILED(rv))
00417       return rv;
00418     if (*value)
00419       nsMemory::Free(*value);
00420     *value = tempStr;
00421 
00422     if (checkValue)
00423       block->GetInt(eCheckboxState, checkValue);  
00424   }
00425   return rv;
00426 }
00427 
00428 NS_IMETHODIMP
00429 nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
00430                     const PRUnichar *dialogTitle, const PRUnichar *text,
00431                     PRUnichar **username, PRUnichar **password,
00432                     const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
00433 
00434 {
00435   NS_ENSURE_ARG(username);
00436   NS_ENSURE_ARG(password);
00437   NS_ENSURE_ARG(_retval);
00438   
00439   nsresult rv;
00440   nsXPIDLString stringOwner;
00441  
00442   if (!dialogTitle) {
00443     rv = GetLocaleString("PromptUsernameAndPassword2", getter_Copies(stringOwner));
00444     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00445     dialogTitle = stringOwner.get();
00446   }
00447 
00448   ParamBlock block;
00449   rv = block.Init();
00450   if (NS_FAILED(rv))
00451     return rv;
00452 
00453   block->SetInt(eNumberButtons, 2);
00454   block->SetString(eMsg, text);
00455 
00456   block->SetString(eDialogTitle, dialogTitle);
00457 
00458   NS_ConvertASCIItoUCS2 styleClass(kQuestionIconClass);
00459   block->SetString(eIconClass, styleClass.get());
00460   block->SetInt( eNumberEditfields, 2 );
00461   if (*username)
00462     block->SetString(eEditfield1Value, *username);
00463   if (*password)
00464     block->SetString(eEditfield2Value, *password);
00465   if (checkMsg && checkValue) {
00466     block->SetString(eCheckboxMsg, checkMsg);
00467     block->SetInt(eCheckboxState, *checkValue);
00468   }
00469   
00470   rv = DoDialog(parent, block, kPromptURL);
00471   if (NS_FAILED(rv))
00472     return rv;
00473 
00474   PRInt32 tempInt = 0;
00475   block->GetInt(eButtonPressed, &tempInt);
00476   *_retval = tempInt ? PR_FALSE : PR_TRUE;
00477   
00478   if (*_retval) {
00479     PRUnichar *tempStr;
00480     
00481     rv = block->GetString(eEditfield1Value, &tempStr);
00482     if (NS_FAILED(rv))
00483       return rv;
00484     if (*username)
00485       nsMemory::Free(*username);
00486     *username = tempStr;
00487 
00488     rv = block->GetString(eEditfield2Value, &tempStr);
00489     if (NS_FAILED(rv))
00490       return rv;
00491     if (*password)
00492       nsMemory::Free(*password);
00493     *password = tempStr;
00494 
00495     if (checkValue)
00496       block->GetInt(eCheckboxState, checkValue);
00497   }
00498   return rv;
00499 }
00500 
00501 NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent,
00502                                 const PRUnichar *dialogTitle, const PRUnichar *text,
00503                                 PRUnichar **password,
00504                                 const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
00505 {
00506   NS_ENSURE_ARG(password);
00507   NS_ENSURE_ARG(_retval);
00508        
00509   nsresult rv;
00510   nsXPIDLString stringOwner;
00511  
00512   if (!dialogTitle) {
00513     rv = GetLocaleString("PromptPassword2", getter_Copies(stringOwner));
00514     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00515     dialogTitle = stringOwner.get();
00516   }
00517 
00518   ParamBlock block;
00519   rv = block.Init();
00520   if (NS_FAILED(rv))
00521     return rv;
00522 
00523   block->SetInt(eNumberButtons, 2);
00524   block->SetString(eMsg, text);
00525 
00526   block->SetString(eDialogTitle, dialogTitle);
00527 
00528   nsString url;
00529   NS_ConvertASCIItoUCS2 styleClass(kQuestionIconClass);
00530   block->SetString(eIconClass, styleClass.get());
00531   block->SetInt(eNumberEditfields, 1);
00532   block->SetInt(eEditField1Password, 1);
00533   if (*password)
00534     block->SetString(eEditfield1Value, *password);
00535   if (checkMsg && checkValue) {
00536     block->SetString(eCheckboxMsg, checkMsg);
00537     block->SetInt(eCheckboxState, *checkValue);
00538   }
00539 
00540   rv = DoDialog(parent, block, kPromptURL);
00541   if (NS_FAILED(rv))
00542     return rv;
00543 
00544   PRInt32 tempInt = 0;
00545   block->GetInt(eButtonPressed, &tempInt);
00546   *_retval = tempInt ? PR_FALSE : PR_TRUE;
00547   if (*_retval) {
00548     PRUnichar *tempStr;
00549     
00550     rv = block->GetString(eEditfield1Value, &tempStr);
00551     if (NS_FAILED(rv))
00552       return rv;
00553     if (*password)
00554       nsMemory::Free(*password);
00555     *password = tempStr;
00556 
00557     if (checkValue)
00558       block->GetInt(eCheckboxState, checkValue);  
00559   }
00560   return rv;
00561 }
00562 
00563 NS_IMETHODIMP
00564 nsPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00565                    const PRUnichar* text, PRUint32 count,
00566                    const PRUnichar **selectList, PRInt32 *outSelection,
00567                    PRBool *_retval)
00568 {      
00569   nsresult rv;
00570   nsXPIDLString stringOwner;
00571  
00572   if (!dialogTitle) {
00573     rv = GetLocaleString("Select", getter_Copies(stringOwner));
00574     if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00575     dialogTitle = stringOwner.get();
00576   }
00577 
00578   const PRInt32 eSelection = 2;
00579   ParamBlock block;
00580   rv = block.Init();
00581   if (NS_FAILED(rv))
00582     return rv;
00583 
00584   block->SetNumberStrings(count + 2);
00585   if (dialogTitle)
00586     block->SetString(0, dialogTitle);
00587   
00588   block->SetString(1, text);
00589   block->SetInt(eSelection, count);
00590   for (PRUint32 i = 2; i <= count+1; i++) {
00591     nsAutoString temp(selectList[i-2]);
00592     const PRUnichar* text = temp.get();
00593     block->SetString(i, text);
00594   }
00595 
00596   *outSelection = -1;
00597   rv = DoDialog(parent, block, kSelectPromptURL);
00598   if (NS_FAILED(rv))
00599     return rv;
00600 
00601   PRInt32 buttonPressed = 0;
00602   block->GetInt(eButtonPressed, &buttonPressed);
00603   block->GetInt(eSelection, outSelection);
00604   *_retval = buttonPressed ? PR_FALSE : PR_TRUE;
00605 
00606   return rv;
00607 }
00608 
00609 /* void showNonBlockingAlert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
00610 NS_IMETHODIMP
00611 nsPromptService::ShowNonBlockingAlert(nsIDOMWindow *aParent,
00612                                       const PRUnichar *aDialogTitle,
00613                                       const PRUnichar *aText)
00614 {
00615   NS_ENSURE_ARG(aParent);
00616   if (!mWatcher)
00617     return NS_ERROR_FAILURE;
00618 
00619   nsCOMPtr<nsIDialogParamBlock> paramBlock(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00620   if (!paramBlock)
00621     return NS_ERROR_FAILURE;
00622 
00623   paramBlock->SetInt(nsPIPromptService::eNumberButtons, 1);
00624   paramBlock->SetString(nsPIPromptService::eIconClass, NS_LITERAL_STRING("alert-icon").get());
00625   paramBlock->SetString(nsPIPromptService::eDialogTitle, aDialogTitle);
00626   paramBlock->SetString(nsPIPromptService::eMsg, aText);
00627 
00628   nsCOMPtr<nsIDOMWindow> dialog;
00629   mWatcher->OpenWindow(aParent, "chrome://global/content/commonDialog.xul",
00630                        "_blank", "dependent,centerscreen,chrome,titlebar",
00631                        paramBlock, getter_AddRefs(dialog));
00632   return NS_OK;
00633 }
00634 
00635 nsresult
00636 nsPromptService::DoDialog(nsIDOMWindow *aParent,
00637                    nsIDialogParamBlock *aParamBlock, const char *aChromeURL)
00638 {
00639   NS_ENSURE_ARG(aParamBlock);
00640   NS_ENSURE_ARG(aChromeURL);
00641   if (!mWatcher)
00642     return NS_ERROR_FAILURE;
00643 
00644   nsresult rv = NS_OK;
00645 
00646   // get a parent, if at all possible
00647   // (though we'd rather this didn't fail, it's OK if it does. so there's
00648   // no failure or null check.)
00649   nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
00650   if (!aParent) {
00651     mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
00652     aParent = activeParent;
00653   }
00654 
00655   nsCOMPtr<nsISupports> arguments(do_QueryInterface(aParamBlock));
00656   nsCOMPtr<nsIDOMWindow> dialog;
00657   rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
00658                             "centerscreen,chrome,modal,titlebar", arguments,
00659                             getter_AddRefs(dialog));
00660 
00661   return rv;
00662 }
00663 
00664 nsresult
00665 nsPromptService::GetLocaleString(const char *aKey, PRUnichar **aResult)
00666 {
00667   nsresult rv;
00668 
00669   nsCOMPtr<nsIStringBundleService> stringService = do_GetService(kStringBundleServiceCID);
00670   nsCOMPtr<nsIStringBundle> stringBundle;
00671  
00672   rv = stringService->CreateBundle(kCommonDialogsProperties, getter_AddRefs(stringBundle));
00673   if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00674 
00675   rv = stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(aKey).get(), aResult);
00676 
00677   return rv;
00678 }
00679