Back to index

lightning-sunbird  0.9+nobinonly
nsFormSigningDialog.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nsFormSigningDialog.h"
00038 #include "nsNSSDialogHelper.h"
00039 #include "nsCOMPtr.h"
00040 #include "nsIDialogParamBlock.h"
00041 #include "nsIComponentManager.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsIInterfaceRequestor.h"
00044 #include "nsIInterfaceRequestorUtils.h"
00045 #include "nsLiteralString.h"
00046 #include "nsXPIDLString.h"
00047 
00048 nsFormSigningDialog::nsFormSigningDialog()
00049 {
00050 }
00051 
00052 nsFormSigningDialog::~nsFormSigningDialog()
00053 {
00054 }
00055 
00056 NS_IMPL_THREADSAFE_ISUPPORTS1(nsFormSigningDialog, nsIFormSigningDialog)
00057 
00058 NS_IMETHODIMP
00059 nsFormSigningDialog::ConfirmSignText(nsIInterfaceRequestor *aContext, 
00060                                      const nsAString &aHost,
00061                                      const nsAString &aSignText,
00062                                      const PRUnichar **aCertNickList,
00063                                      const PRUnichar **aCertDetailsList,
00064                                      PRUint32 aCount, PRInt32 *aSelectedIndex,
00065                                      nsAString &aPassword, PRBool *aCanceled) 
00066 {
00067   *aCanceled = PR_TRUE;
00068 
00069   // Get the parent window for the dialog
00070   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(aContext);
00071 
00072   nsresult rv;
00073   nsCOMPtr<nsIDialogParamBlock> block =
00074     do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &rv);
00075   NS_ENSURE_SUCCESS(rv, rv);
00076 
00077   block->SetNumberStrings(3 + aCount * 2);
00078 
00079   rv = block->SetString(0, PromiseFlatString(aHost).get());
00080   NS_ENSURE_SUCCESS(rv, rv);
00081 
00082   rv = block->SetString(1, PromiseFlatString(aSignText).get());
00083   NS_ENSURE_SUCCESS(rv, rv);
00084 
00085   PRUint32 i;
00086   for (i = 0; i < aCount; ++i) {
00087     rv = block->SetString(2 + 2 * i, aCertNickList[i]);
00088     NS_ENSURE_SUCCESS(rv, rv);
00089 
00090     rv = block->SetString(2 + (2 * i + 1), aCertDetailsList[i]);
00091     NS_ENSURE_SUCCESS(rv, rv);
00092   }
00093 
00094   rv = block->SetInt(0, aCount);
00095   NS_ENSURE_SUCCESS(rv, rv);
00096 
00097   rv = nsNSSDialogHelper::openDialog(parent,
00098                                      "chrome://pippki/content/formsigning.xul",
00099                                      block);
00100   NS_ENSURE_SUCCESS(rv, rv);
00101 
00102   PRInt32 status;
00103   rv = block->GetInt(0, &status);
00104   NS_ENSURE_SUCCESS(rv, rv);
00105 
00106   if (status == 0) {
00107     *aCanceled = PR_TRUE;
00108   }
00109   else {
00110     *aCanceled = PR_FALSE;
00111 
00112     rv = block->GetInt(1, aSelectedIndex);
00113     NS_ENSURE_SUCCESS(rv, rv);
00114 
00115     nsXPIDLString pw;
00116     rv = block->GetString(0, getter_Copies(pw));
00117     NS_ENSURE_SUCCESS(rv, rv);
00118 
00119     aPassword = pw;
00120   }
00121 
00122   return NS_OK;
00123 }