security/manager/pki/src/nsFormSigningDialog.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/pki/src/nsFormSigningDialog.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsFormSigningDialog.h"
     1.9 +#include "nsNSSDialogHelper.h"
    1.10 +#include "nsCOMPtr.h"
    1.11 +#include "nsIDialogParamBlock.h"
    1.12 +#include "nsIComponentManager.h"
    1.13 +#include "nsIServiceManager.h"
    1.14 +#include "nsIInterfaceRequestor.h"
    1.15 +#include "nsIInterfaceRequestorUtils.h"
    1.16 +#include "nsLiteralString.h"
    1.17 +#include "nsXPIDLString.h"
    1.18 +
    1.19 +nsFormSigningDialog::nsFormSigningDialog()
    1.20 +{
    1.21 +}
    1.22 +
    1.23 +nsFormSigningDialog::~nsFormSigningDialog()
    1.24 +{
    1.25 +}
    1.26 +
    1.27 +NS_IMPL_ISUPPORTS(nsFormSigningDialog, nsIFormSigningDialog)
    1.28 +
    1.29 +NS_IMETHODIMP
    1.30 +nsFormSigningDialog::ConfirmSignText(nsIInterfaceRequestor *aContext, 
    1.31 +                                     const nsAString &aHost,
    1.32 +                                     const nsAString &aSignText,
    1.33 +                                     const char16_t **aCertNickList,
    1.34 +                                     const char16_t **aCertDetailsList,
    1.35 +                                     uint32_t aCount, int32_t *aSelectedIndex,
    1.36 +                                     nsAString &aPassword, bool *aCanceled) 
    1.37 +{
    1.38 +  *aCanceled = true;
    1.39 +
    1.40 +  // Get the parent window for the dialog
    1.41 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aContext);
    1.42 +
    1.43 +  nsresult rv;
    1.44 +  nsCOMPtr<nsIDialogParamBlock> block =
    1.45 +    do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &rv);
    1.46 +  NS_ENSURE_SUCCESS(rv, rv);
    1.47 +
    1.48 +  block->SetNumberStrings(3 + aCount * 2);
    1.49 +
    1.50 +  rv = block->SetString(0, PromiseFlatString(aHost).get());
    1.51 +  NS_ENSURE_SUCCESS(rv, rv);
    1.52 +
    1.53 +  rv = block->SetString(1, PromiseFlatString(aSignText).get());
    1.54 +  NS_ENSURE_SUCCESS(rv, rv);
    1.55 +
    1.56 +  uint32_t i;
    1.57 +  for (i = 0; i < aCount; ++i) {
    1.58 +    rv = block->SetString(2 + 2 * i, aCertNickList[i]);
    1.59 +    NS_ENSURE_SUCCESS(rv, rv);
    1.60 +
    1.61 +    rv = block->SetString(2 + (2 * i + 1), aCertDetailsList[i]);
    1.62 +    NS_ENSURE_SUCCESS(rv, rv);
    1.63 +  }
    1.64 +
    1.65 +  rv = block->SetInt(0, aCount);
    1.66 +  NS_ENSURE_SUCCESS(rv, rv);
    1.67 +
    1.68 +  rv = nsNSSDialogHelper::openDialog(parent,
    1.69 +                                     "chrome://pippki/content/formsigning.xul",
    1.70 +                                     block);
    1.71 +  NS_ENSURE_SUCCESS(rv, rv);
    1.72 +
    1.73 +  int32_t status;
    1.74 +  rv = block->GetInt(0, &status);
    1.75 +  NS_ENSURE_SUCCESS(rv, rv);
    1.76 +
    1.77 +  if (status == 0) {
    1.78 +    *aCanceled = true;
    1.79 +  }
    1.80 +  else {
    1.81 +    *aCanceled = false;
    1.82 +
    1.83 +    rv = block->GetInt(1, aSelectedIndex);
    1.84 +    NS_ENSURE_SUCCESS(rv, rv);
    1.85 +
    1.86 +    nsXPIDLString pw;
    1.87 +    rv = block->GetString(0, getter_Copies(pw));
    1.88 +    NS_ENSURE_SUCCESS(rv, rv);
    1.89 +
    1.90 +    aPassword = pw;
    1.91 +  }
    1.92 +
    1.93 +  return NS_OK;
    1.94 +}

mercurial