security/manager/pki/src/nsNSSDialogs.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/pki/src/nsNSSDialogs.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,598 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 + * Dialog services for PIP.
    1.12 + */
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsString.h"
    1.15 +#include "nsXPIDLString.h"
    1.16 +#include "nsReadableUtils.h"
    1.17 +#include "nsIDOMWindow.h"
    1.18 +#include "nsIDialogParamBlock.h"
    1.19 +#include "nsIComponentManager.h"
    1.20 +#include "nsIServiceManager.h"
    1.21 +#include "nsIStringBundle.h"
    1.22 +#include "nsIInterfaceRequestor.h"
    1.23 +#include "nsIInterfaceRequestorUtils.h"
    1.24 +#include "nsIX509Cert.h"
    1.25 +#include "nsIX509CertDB.h"
    1.26 +#include "nsIDateTimeFormat.h"
    1.27 +#include "nsDateTimeFormatCID.h"
    1.28 +#include "nsPromiseFlatString.h"
    1.29 +
    1.30 +#include "nsNSSDialogs.h"
    1.31 +#include "nsPKIParamBlock.h"
    1.32 +#include "nsIKeygenThread.h"
    1.33 +#include "nsIProtectedAuthThread.h"
    1.34 +#include "nsNSSDialogHelper.h"
    1.35 +#include "nsIWindowWatcher.h"
    1.36 +#include "nsIX509CertValidity.h"
    1.37 +
    1.38 +#include "nsEmbedCID.h"
    1.39 +#include "nsIPromptService.h"
    1.40 +
    1.41 +#define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
    1.42 +
    1.43 +/* ==== */
    1.44 +
    1.45 +nsNSSDialogs::nsNSSDialogs()
    1.46 +{
    1.47 +}
    1.48 +
    1.49 +nsNSSDialogs::~nsNSSDialogs()
    1.50 +{
    1.51 +}
    1.52 +
    1.53 +NS_IMPL_ISUPPORTS(nsNSSDialogs, nsITokenPasswordDialogs,
    1.54 +                  nsICertificateDialogs,
    1.55 +                  nsIClientAuthDialogs,
    1.56 +                  nsICertPickDialogs,
    1.57 +                  nsITokenDialogs,
    1.58 +                  nsIDOMCryptoDialogs,
    1.59 +                  nsIGeneratingKeypairInfoDialogs,
    1.60 +                  nsISSLCertErrorDialog)
    1.61 +
    1.62 +nsresult
    1.63 +nsNSSDialogs::Init()
    1.64 +{
    1.65 +  nsresult rv;
    1.66 +
    1.67 +  nsCOMPtr<nsIStringBundleService> service =
    1.68 +           do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
    1.69 +  if (NS_FAILED(rv)) return rv;
    1.70 +  
    1.71 +  rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
    1.72 +                             getter_AddRefs(mPIPStringBundle));
    1.73 +  return rv;
    1.74 +}
    1.75 +
    1.76 +nsresult
    1.77 +nsNSSDialogs::SetPassword(nsIInterfaceRequestor *ctx,
    1.78 +                          const char16_t *tokenName, bool* _canceled)
    1.79 +{
    1.80 +  nsresult rv;
    1.81 +
    1.82 +  *_canceled = false;
    1.83 +
    1.84 +  // Get the parent window for the dialog
    1.85 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
    1.86 +
    1.87 +  nsCOMPtr<nsIDialogParamBlock> block =
    1.88 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
    1.89 +  if (!block) return NS_ERROR_FAILURE;
    1.90 +
    1.91 +  // void ChangePassword(in wstring tokenName, out int status);
    1.92 +  rv = block->SetString(1, tokenName);
    1.93 +  if (NS_FAILED(rv)) return rv;
    1.94 +
    1.95 +  rv = nsNSSDialogHelper::openDialog(parent,
    1.96 +                                "chrome://pippki/content/changepassword.xul",
    1.97 +                                block);
    1.98 +
    1.99 +  if (NS_FAILED(rv)) return rv;
   1.100 +
   1.101 +  int32_t status;
   1.102 +
   1.103 +  rv = block->GetInt(1, &status);
   1.104 +  if (NS_FAILED(rv)) return rv;
   1.105 +
   1.106 +  *_canceled = (status == 0)?true:false;
   1.107 +
   1.108 +  return rv;
   1.109 +}
   1.110 +
   1.111 +nsresult
   1.112 +nsNSSDialogs::GetPassword(nsIInterfaceRequestor *ctx,
   1.113 +                          const char16_t *tokenName, 
   1.114 +                          char16_t **_password,
   1.115 +                          bool* _canceled)
   1.116 +{
   1.117 +  nsresult rv;
   1.118 +  *_canceled = false;
   1.119 +  // Get the parent window for the dialog
   1.120 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.121 +  nsCOMPtr<nsIDialogParamBlock> block = 
   1.122 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.123 +  if (!block) return NS_ERROR_FAILURE;
   1.124 +  // Set the token name in the window
   1.125 +  rv = block->SetString(1, tokenName);
   1.126 +  if (NS_FAILED(rv)) return rv;
   1.127 +  // open up the window
   1.128 +  rv = nsNSSDialogHelper::openDialog(parent,
   1.129 +                                     "chrome://pippki/content/getpassword.xul",
   1.130 +                                     block);
   1.131 +  if (NS_FAILED(rv)) return rv;
   1.132 +  // see if user canceled
   1.133 +  int32_t status;
   1.134 +  rv = block->GetInt(1, &status);
   1.135 +  if (NS_FAILED(rv)) return rv;
   1.136 +  *_canceled = (status == 0) ? true : false;
   1.137 +  if (!*_canceled) {
   1.138 +    // retrieve the password
   1.139 +    rv = block->GetString(2, _password);
   1.140 +  }
   1.141 +  return rv;
   1.142 +}
   1.143 +
   1.144 +NS_IMETHODIMP 
   1.145 +nsNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, 
   1.146 +                                    nsIX509Cert *cert,
   1.147 +                                    uint32_t *_trust,
   1.148 +                                    bool *_retval)
   1.149 +{
   1.150 +  nsresult rv;
   1.151 +
   1.152 +  *_retval = true;
   1.153 +
   1.154 +  // Get the parent window for the dialog
   1.155 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.156 +
   1.157 +  nsCOMPtr<nsIPKIParamBlock> block =
   1.158 +           do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
   1.159 +  if (!block)
   1.160 +    return NS_ERROR_FAILURE;
   1.161 +
   1.162 +  rv = block->SetISupportAtIndex(1, cert);
   1.163 +  if (NS_FAILED(rv))
   1.164 +    return rv;
   1.165 +
   1.166 +  rv = nsNSSDialogHelper::openDialog(parent, 
   1.167 +                                     "chrome://pippki/content/downloadcert.xul",
   1.168 +                                     block);
   1.169 +  if (NS_FAILED(rv)) return rv;
   1.170 +
   1.171 +  int32_t status;
   1.172 +  int32_t ssl, email, objsign;
   1.173 +
   1.174 +  nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
   1.175 +  
   1.176 +  rv = dlgParamBlock->GetInt(1, &status);
   1.177 +  if (NS_FAILED(rv)) return rv;
   1.178 +  rv = dlgParamBlock->GetInt(2, &ssl);
   1.179 +  if (NS_FAILED(rv)) return rv;
   1.180 +  rv = dlgParamBlock->GetInt(3, &email);
   1.181 +  if (NS_FAILED(rv)) return rv;
   1.182 +  rv = dlgParamBlock->GetInt(4, &objsign);
   1.183 +  if (NS_FAILED(rv)) return rv;
   1.184 + 
   1.185 +  *_trust = nsIX509CertDB::UNTRUSTED;
   1.186 +  *_trust |= (ssl) ? nsIX509CertDB::TRUSTED_SSL : 0;
   1.187 +  *_trust |= (email) ? nsIX509CertDB::TRUSTED_EMAIL : 0;
   1.188 +  *_trust |= (objsign) ? nsIX509CertDB::TRUSTED_OBJSIGN : 0;
   1.189 +
   1.190 +  *_retval = (status == 0)?false:true;
   1.191 +
   1.192 +  return rv;
   1.193 +}
   1.194 +
   1.195 +
   1.196 +NS_IMETHODIMP 
   1.197 +nsNSSDialogs::NotifyCACertExists(nsIInterfaceRequestor *ctx)
   1.198 +{
   1.199 +  nsresult rv;
   1.200 +
   1.201 +  nsCOMPtr<nsIPromptService> promptSvc(do_GetService(NS_PROMPTSERVICE_CONTRACTID));
   1.202 +  if (!promptSvc)
   1.203 +    return NS_ERROR_FAILURE;
   1.204 +
   1.205 +  // Get the parent window for the dialog
   1.206 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.207 +
   1.208 +  nsAutoString title;
   1.209 +  rv = mPIPStringBundle->GetStringFromName(MOZ_UTF16("caCertExistsTitle"),
   1.210 +                                           getter_Copies(title));
   1.211 +  NS_ENSURE_SUCCESS(rv, rv);
   1.212 +
   1.213 +  nsAutoString msg;
   1.214 +  rv = mPIPStringBundle->GetStringFromName(MOZ_UTF16("caCertExistsMessage"),
   1.215 +                                           getter_Copies(msg));
   1.216 +  NS_ENSURE_SUCCESS(rv, rv);
   1.217 +
   1.218 +  rv = promptSvc->Alert(parent, title.get(), msg.get());
   1.219 +
   1.220 +  return rv;
   1.221 +}
   1.222 +
   1.223 +
   1.224 +NS_IMETHODIMP
   1.225 +nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor *ctx, const char16_t *cn, const char16_t *organization, const char16_t *issuer, const char16_t **certNickList, const char16_t **certDetailsList, uint32_t count, int32_t *selectedIndex, bool *canceled) 
   1.226 +{
   1.227 +  nsresult rv;
   1.228 +  uint32_t i;
   1.229 +
   1.230 +  *canceled = false;
   1.231 +
   1.232 +  // Get the parent window for the dialog
   1.233 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.234 +
   1.235 +  nsCOMPtr<nsIDialogParamBlock> block =
   1.236 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.237 +  if (!block) return NS_ERROR_FAILURE;
   1.238 +
   1.239 +  block->SetNumberStrings(4+count*2);
   1.240 +
   1.241 +  rv = block->SetString(0, cn);
   1.242 +  if (NS_FAILED(rv)) return rv;
   1.243 +
   1.244 +  rv = block->SetString(1, organization);
   1.245 +  if (NS_FAILED(rv)) return rv;
   1.246 +
   1.247 +  rv = block->SetString(2, issuer);
   1.248 +  if (NS_FAILED(rv)) return rv;
   1.249 +
   1.250 +  for (i = 0; i < count; i++) {
   1.251 +    rv = block->SetString(i+3, certNickList[i]);
   1.252 +    if (NS_FAILED(rv)) return rv;
   1.253 +  }
   1.254 +
   1.255 +  for (i = 0; i < count; i++) {
   1.256 +    rv = block->SetString(i+count+3, certDetailsList[i]);
   1.257 +    if (NS_FAILED(rv)) return rv;
   1.258 +  }
   1.259 +
   1.260 +  rv = block->SetInt(0, count);
   1.261 +  if (NS_FAILED(rv)) return rv;
   1.262 +
   1.263 +  rv = nsNSSDialogHelper::openDialog(nullptr,
   1.264 +                                "chrome://pippki/content/clientauthask.xul",
   1.265 +                                block);
   1.266 +  if (NS_FAILED(rv)) return rv;
   1.267 +
   1.268 +  int32_t status;
   1.269 +  rv = block->GetInt(0, &status);
   1.270 +  if (NS_FAILED(rv)) return rv;
   1.271 +
   1.272 +  nsCOMPtr<nsIClientAuthUserDecision> extraResult = do_QueryInterface(ctx);
   1.273 +  if (extraResult) {
   1.274 +    int32_t rememberSelection;
   1.275 +    rv = block->GetInt(2, &rememberSelection);
   1.276 +    if (NS_SUCCEEDED(rv)) {
   1.277 +      extraResult->SetRememberClientAuthCertificate(rememberSelection!=0);
   1.278 +    }
   1.279 +  }
   1.280 +
   1.281 +  *canceled = (status == 0)?true:false;
   1.282 +  if (!*canceled) {
   1.283 +    // retrieve the nickname
   1.284 +    rv = block->GetInt(1, selectedIndex);
   1.285 +  }
   1.286 +  return rv;
   1.287 +}
   1.288 +
   1.289 +
   1.290 +NS_IMETHODIMP
   1.291 +nsNSSDialogs::PickCertificate(nsIInterfaceRequestor *ctx, 
   1.292 +                              const char16_t **certNickList, 
   1.293 +                              const char16_t **certDetailsList, 
   1.294 +                              uint32_t count, 
   1.295 +                              int32_t *selectedIndex, 
   1.296 +                              bool *canceled) 
   1.297 +{
   1.298 +  nsresult rv;
   1.299 +  uint32_t i;
   1.300 +
   1.301 +  *canceled = false;
   1.302 +
   1.303 +  // Get the parent window for the dialog
   1.304 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.305 +
   1.306 +  nsCOMPtr<nsIDialogParamBlock> block =
   1.307 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.308 +  if (!block) return NS_ERROR_FAILURE;
   1.309 +
   1.310 +  block->SetNumberStrings(1+count*2);
   1.311 +
   1.312 +  for (i = 0; i < count; i++) {
   1.313 +    rv = block->SetString(i, certNickList[i]);
   1.314 +    if (NS_FAILED(rv)) return rv;
   1.315 +  }
   1.316 +
   1.317 +  for (i = 0; i < count; i++) {
   1.318 +    rv = block->SetString(i+count, certDetailsList[i]);
   1.319 +    if (NS_FAILED(rv)) return rv;
   1.320 +  }
   1.321 +
   1.322 +  rv = block->SetInt(0, count);
   1.323 +  if (NS_FAILED(rv)) return rv;
   1.324 +
   1.325 +  rv = block->SetInt(1, *selectedIndex);
   1.326 +  if (NS_FAILED(rv)) return rv;
   1.327 +
   1.328 +  rv = nsNSSDialogHelper::openDialog(nullptr,
   1.329 +                                "chrome://pippki/content/certpicker.xul",
   1.330 +                                block);
   1.331 +  if (NS_FAILED(rv)) return rv;
   1.332 +
   1.333 +  int32_t status;
   1.334 +
   1.335 +  rv = block->GetInt(0, &status);
   1.336 +  if (NS_FAILED(rv)) return rv;
   1.337 +
   1.338 +  *canceled = (status == 0)?true:false;
   1.339 +  if (!*canceled) {
   1.340 +    rv = block->GetInt(1, selectedIndex);
   1.341 +  }
   1.342 +  return rv;
   1.343 +}
   1.344 +
   1.345 +
   1.346 +NS_IMETHODIMP 
   1.347 +nsNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, 
   1.348 +                                    nsAString &_password,
   1.349 +                                    bool *_retval)
   1.350 +{
   1.351 +  nsresult rv;
   1.352 +  *_retval = true;
   1.353 +  // Get the parent window for the dialog
   1.354 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.355 +  nsCOMPtr<nsIDialogParamBlock> block =
   1.356 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.357 +  if (!block) return NS_ERROR_FAILURE;
   1.358 +  // open up the window
   1.359 +  rv = nsNSSDialogHelper::openDialog(parent,
   1.360 +                                  "chrome://pippki/content/setp12password.xul",
   1.361 +                                  block);
   1.362 +  if (NS_FAILED(rv)) return rv;
   1.363 +  // see if user canceled
   1.364 +  int32_t status;
   1.365 +  rv = block->GetInt(1, &status);
   1.366 +  if (NS_FAILED(rv)) return rv;
   1.367 +  *_retval = (status == 0) ? false : true;
   1.368 +  if (*_retval) {
   1.369 +    // retrieve the password
   1.370 +    char16_t *pw;
   1.371 +    rv = block->GetString(2, &pw);
   1.372 +    if (NS_SUCCEEDED(rv)) {
   1.373 +      _password = pw;
   1.374 +      nsMemory::Free(pw);
   1.375 +    }
   1.376 +  }
   1.377 +  return rv;
   1.378 +}
   1.379 +
   1.380 +NS_IMETHODIMP 
   1.381 +nsNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, 
   1.382 +                                    nsAString &_password,
   1.383 +                                    bool *_retval)
   1.384 +{
   1.385 +  nsresult rv;
   1.386 +  *_retval = true;
   1.387 +  // Get the parent window for the dialog
   1.388 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.389 +  nsCOMPtr<nsIDialogParamBlock> block =
   1.390 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.391 +  if (!block) return NS_ERROR_FAILURE;
   1.392 +  // open up the window
   1.393 +  rv = nsNSSDialogHelper::openDialog(parent,
   1.394 +                                  "chrome://pippki/content/getp12password.xul",
   1.395 +                                  block);
   1.396 +  if (NS_FAILED(rv)) return rv;
   1.397 +  // see if user canceled
   1.398 +  int32_t status;
   1.399 +  rv = block->GetInt(1, &status);
   1.400 +  if (NS_FAILED(rv)) return rv;
   1.401 +  *_retval = (status == 0) ? false : true;
   1.402 +  if (*_retval) {
   1.403 +    // retrieve the password
   1.404 +    char16_t *pw;
   1.405 +    rv = block->GetString(2, &pw);
   1.406 +    if (NS_SUCCEEDED(rv)) {
   1.407 +      _password = pw;
   1.408 +      nsMemory::Free(pw);
   1.409 +    }
   1.410 +  }
   1.411 +  return rv;
   1.412 +}
   1.413 +
   1.414 +/* void viewCert (in nsIX509Cert cert); */
   1.415 +NS_IMETHODIMP 
   1.416 +nsNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, 
   1.417 +                       nsIX509Cert *cert)
   1.418 +{
   1.419 +  nsresult rv;
   1.420 +
   1.421 +  nsCOMPtr<nsIPKIParamBlock> block =
   1.422 +           do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
   1.423 +  if (!block)
   1.424 +    return NS_ERROR_FAILURE;
   1.425 +
   1.426 +  rv = block->SetISupportAtIndex(1, cert);
   1.427 +  if (NS_FAILED(rv))
   1.428 +    return rv;
   1.429 +
   1.430 +  // Get the parent window for the dialog
   1.431 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
   1.432 +
   1.433 +  rv = nsNSSDialogHelper::openDialog(parent,
   1.434 +                                     "chrome://pippki/content/certViewer.xul",
   1.435 +                                     block,
   1.436 +                                     false);
   1.437 +  return rv;
   1.438 +}
   1.439 +
   1.440 +NS_IMETHODIMP
   1.441 +nsNSSDialogs::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable) 
   1.442 +{
   1.443 +  nsresult rv;
   1.444 +
   1.445 +  // Get the parent window for the dialog
   1.446 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
   1.447 +
   1.448 +  rv = nsNSSDialogHelper::openDialog(parent,
   1.449 +                                     "chrome://pippki/content/createCertInfo.xul",
   1.450 +                                     runnable);
   1.451 +  return rv;
   1.452 +}
   1.453 +
   1.454 +NS_IMETHODIMP
   1.455 +nsNSSDialogs::ChooseToken(nsIInterfaceRequestor *aCtx, const char16_t **aTokenList, uint32_t aCount, char16_t **aTokenChosen, bool *aCanceled) {
   1.456 +  nsresult rv;
   1.457 +  uint32_t i;
   1.458 +
   1.459 +  *aCanceled = false;
   1.460 +
   1.461 +  // Get the parent window for the dialog
   1.462 +  nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
   1.463 +
   1.464 +  nsCOMPtr<nsIDialogParamBlock> block =
   1.465 +           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
   1.466 +  if (!block) return NS_ERROR_FAILURE;
   1.467 +
   1.468 +  block->SetNumberStrings(aCount);
   1.469 +
   1.470 +  for (i = 0; i < aCount; i++) {
   1.471 +    rv = block->SetString(i, aTokenList[i]);
   1.472 +    if (NS_FAILED(rv)) return rv;
   1.473 +  }
   1.474 +
   1.475 +  rv = block->SetInt(0, aCount);
   1.476 +  if (NS_FAILED(rv)) return rv;
   1.477 +
   1.478 +  rv = nsNSSDialogHelper::openDialog(nullptr,
   1.479 +                                "chrome://pippki/content/choosetoken.xul",
   1.480 +                                block);
   1.481 +  if (NS_FAILED(rv)) return rv;
   1.482 +
   1.483 +  int32_t status;
   1.484 +
   1.485 +  rv = block->GetInt(0, &status);
   1.486 +  if (NS_FAILED(rv)) return rv;
   1.487 +
   1.488 +  *aCanceled = (status == 0)?true:false;
   1.489 +  if (!*aCanceled) {
   1.490 +    // retrieve the nickname
   1.491 +    rv = block->GetString(0, aTokenChosen);
   1.492 +  }
   1.493 +  return rv;
   1.494 +}
   1.495 +
   1.496 +/* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */
   1.497 +NS_IMETHODIMP 
   1.498 +nsNSSDialogs::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, bool *_retval)
   1.499 +                                     
   1.500 +{
   1.501 +  *_retval = false;
   1.502 +
   1.503 +  nsresult rv;
   1.504 +
   1.505 +  nsCOMPtr<nsIPKIParamBlock> block =
   1.506 +           do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
   1.507 +  if (!block)
   1.508 +    return NS_ERROR_FAILURE;
   1.509 +
   1.510 +  rv = block->SetISupportAtIndex(1, escrowAuthority);
   1.511 +  if (NS_FAILED(rv))
   1.512 +    return rv;
   1.513 +
   1.514 +  rv = nsNSSDialogHelper::openDialog(nullptr,
   1.515 +                                     "chrome://pippki/content/escrowWarn.xul",
   1.516 +                                     block);
   1.517 +
   1.518 +  if (NS_FAILED(rv))
   1.519 +    return rv;
   1.520 +
   1.521 +  int32_t status=0;
   1.522 +  nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
   1.523 +  rv = dlgParamBlock->GetInt(1, &status);
   1.524 + 
   1.525 +  if (status) {
   1.526 +    *_retval = true;
   1.527 +  } 
   1.528 +  return rv;
   1.529 +}
   1.530 +
   1.531 +NS_IMETHODIMP
   1.532 +nsNSSDialogs::DisplayProtectedAuth(nsIInterfaceRequestor *aCtx, nsIProtectedAuthThread *runnable)
   1.533 +{
   1.534 +    // We cannot use nsNSSDialogHelper here. We cannot allow close widget
   1.535 +    // in the window because protected authentication is interruptible
   1.536 +    // from user interface and changing nsNSSDialogHelper's static variable
   1.537 +    // would not be thread-safe
   1.538 +    
   1.539 +    nsresult rv = NS_ERROR_FAILURE;
   1.540 +    
   1.541 +    // Get the parent window for the dialog
   1.542 +    nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
   1.543 +    
   1.544 +    nsCOMPtr<nsIWindowWatcher> windowWatcher = 
   1.545 +        do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
   1.546 +    if (NS_FAILED(rv))
   1.547 +        return rv;
   1.548 +    
   1.549 +    if (!parent) {
   1.550 +        windowWatcher->GetActiveWindow(getter_AddRefs(parent));
   1.551 +    }
   1.552 +    
   1.553 +    nsCOMPtr<nsIDOMWindow> newWindow;
   1.554 +    rv = windowWatcher->OpenWindow(parent,
   1.555 +        "chrome://pippki/content/protectedAuth.xul",
   1.556 +        "_blank",
   1.557 +        "centerscreen,chrome,modal,titlebar,close=no",
   1.558 +        runnable,
   1.559 +        getter_AddRefs(newWindow));
   1.560 +    
   1.561 +    return rv;
   1.562 +}
   1.563 +
   1.564 +NS_IMETHODIMP
   1.565 +nsNSSDialogs::ShowCertError(nsIInterfaceRequestor *ctx, 
   1.566 +                            nsISSLStatus *status, 
   1.567 +                            nsIX509Cert *cert, 
   1.568 +                            const nsAString & textErrorMessage, 
   1.569 +                            const nsAString & htmlErrorMessage, 
   1.570 +                            const nsACString & hostName, 
   1.571 +                            uint32_t portNumber)
   1.572 +{
   1.573 +  nsCOMPtr<nsIPKIParamBlock> block =
   1.574 +           do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
   1.575 +  if (!block)
   1.576 +    return NS_ERROR_OUT_OF_MEMORY;
   1.577 +
   1.578 +  nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
   1.579 +
   1.580 +  nsresult rv;
   1.581 +  rv = dialogBlock->SetInt(1, portNumber);
   1.582 +  if (NS_FAILED(rv))
   1.583 +    return rv; 
   1.584 +
   1.585 +  rv = dialogBlock->SetString(1, NS_ConvertUTF8toUTF16(hostName).get());
   1.586 +  if (NS_FAILED(rv))
   1.587 +    return rv;
   1.588 +  
   1.589 +  rv = dialogBlock->SetString(2, PromiseFlatString(textErrorMessage).get());
   1.590 +  if (NS_FAILED(rv))
   1.591 +    return rv;
   1.592 +  
   1.593 +  rv = block->SetISupportAtIndex(1, cert);
   1.594 +  if (NS_FAILED(rv))
   1.595 +    return rv;
   1.596 +
   1.597 +  rv = nsNSSDialogHelper::openDialog(nullptr, 
   1.598 +                                     "chrome://pippki/content/certerror.xul",
   1.599 +                                     block);
   1.600 +  return rv;
   1.601 +}

mercurial