2001-02-07 04:25:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-31 13:33:35 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-02-07 04:25:16 +03:00
|
|
|
|
|
|
|
/*
|
2001-02-14 23:09:33 +03:00
|
|
|
* Dialog services for PIP.
|
2001-02-07 04:25:16 +03:00
|
|
|
*/
|
2016-10-20 19:33:36 +03:00
|
|
|
|
|
|
|
#include "nsNSSDialogs.h"
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
#include "mozIDOMWindow.h"
|
2016-03-25 16:36:25 +03:00
|
|
|
#include "nsArray.h"
|
|
|
|
#include "nsEmbedCID.h"
|
2016-10-23 07:57:41 +03:00
|
|
|
#include "nsHashPropertyBag.h"
|
2016-03-25 16:36:25 +03:00
|
|
|
#include "nsIDialogParamBlock.h"
|
2001-02-14 23:09:33 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:27:22 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2001-08-16 03:27:42 +04:00
|
|
|
#include "nsIKeygenThread.h"
|
2018-06-01 00:46:06 +03:00
|
|
|
#include "nsIPK11Token.h"
|
2016-03-25 16:36:25 +03:00
|
|
|
#include "nsIPromptService.h"
|
2007-12-05 10:34:55 +03:00
|
|
|
#include "nsIProtectedAuthThread.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
2016-03-25 16:36:25 +03:00
|
|
|
#include "nsIX509CertDB.h"
|
|
|
|
#include "nsIX509Cert.h"
|
|
|
|
#include "nsNSSDialogHelper.h"
|
2017-02-26 15:36:40 +03:00
|
|
|
#include "nsPromiseFlatString.h"
|
2016-03-25 16:36:25 +03:00
|
|
|
#include "nsString.h"
|
2016-10-23 07:57:41 +03:00
|
|
|
#include "nsVariant.h"
|
2013-05-30 04:56:09 +04:00
|
|
|
|
2001-02-24 03:20:32 +03:00
|
|
|
#define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
|
2001-02-14 23:09:33 +03:00
|
|
|
|
2001-02-07 04:25:16 +03:00
|
|
|
nsNSSDialogs::nsNSSDialogs() {}
|
|
|
|
|
|
|
|
nsNSSDialogs::~nsNSSDialogs() {}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsNSSDialogs, nsITokenPasswordDialogs, nsICertificateDialogs,
|
|
|
|
nsIClientAuthDialogs, nsITokenDialogs,
|
2014-06-10 03:35:35 +04:00
|
|
|
nsIGeneratingKeypairInfoDialogs)
|
2001-05-02 09:38:26 +04:00
|
|
|
|
2001-02-14 23:09:33 +03:00
|
|
|
nsresult nsNSSDialogs::Init() {
|
|
|
|
nsresult rv;
|
|
|
|
|
2007-09-05 17:04:54 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> service =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
2001-02-14 23:09:33 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-04-28 01:31:24 +04:00
|
|
|
rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
|
2001-02-24 03:20:32 +03:00
|
|
|
getter_AddRefs(mPIPStringBundle));
|
2001-02-14 23:09:33 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2001-02-07 04:25:16 +03:00
|
|
|
|
2017-02-26 15:36:40 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNSSDialogs::SetPassword(nsIInterfaceRequestor* ctx, nsIPK11Token* token,
|
|
|
|
/*out*/ bool* canceled) {
|
|
|
|
// |ctx| is allowed to be null.
|
|
|
|
NS_ENSURE_ARG(canceled);
|
2001-02-07 04:25:16 +03:00
|
|
|
|
2017-02-26 15:36:40 +03:00
|
|
|
*canceled = false;
|
2001-02-07 04:25:16 +03:00
|
|
|
|
2001-02-14 23:09:33 +03:00
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(ctx);
|
2001-02-07 04:25:16 +03:00
|
|
|
|
2007-09-05 17:04:54 +04:00
|
|
|
nsCOMPtr<nsIDialogParamBlock> block =
|
|
|
|
do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
|
2001-02-07 04:25:16 +03:00
|
|
|
if (!block) return NS_ERROR_FAILURE;
|
|
|
|
|
2018-06-01 00:46:06 +03:00
|
|
|
nsCOMPtr<nsIMutableArray> objects = nsArrayBase::Create();
|
|
|
|
if (!objects) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsresult rv = objects->AppendElement(token);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = block->SetObjects(objects);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-14 23:09:33 +03:00
|
|
|
|
2001-02-24 03:20:32 +03:00
|
|
|
rv = nsNSSDialogHelper::openDialog(
|
2001-02-07 20:35:40 +03:00
|
|
|
parent, "chrome://pippki/content/changepassword.xul", block);
|
2001-02-24 03:20:32 +03:00
|
|
|
|
2001-02-07 04:25:16 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t status;
|
2001-02-07 04:25:16 +03:00
|
|
|
|
|
|
|
rv = block->GetInt(1, &status);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2017-02-26 15:36:40 +03:00
|
|
|
*canceled = (status == 0);
|
2001-02-07 04:25:16 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-10 05:53:10 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor* ctx,
|
|
|
|
nsIX509Cert* cert,
|
|
|
|
/*out*/ uint32_t* trust,
|
|
|
|
/*out*/ bool* importConfirmed) {
|
|
|
|
// |ctx| is allowed to be null.
|
|
|
|
NS_ENSURE_ARG(cert);
|
|
|
|
NS_ENSURE_ARG(trust);
|
|
|
|
NS_ENSURE_ARG(importConfirmed);
|
2001-02-27 00:50:54 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
nsCOMPtr<nsIMutableArray> argArray = nsArrayBase::Create();
|
|
|
|
if (!argArray) {
|
2001-08-21 05:11:29 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-10-22 23:11:40 +03:00
|
|
|
}
|
2016-10-27 21:13:38 +03:00
|
|
|
|
2017-10-21 17:53:02 +03:00
|
|
|
nsresult rv = argArray->AppendElement(cert);
|
2015-10-22 23:11:40 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-10-27 21:13:38 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> retVals = new nsHashPropertyBag();
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(retVals);
|
2015-10-22 23:11:40 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-02-27 00:50:54 +03:00
|
|
|
return rv;
|
2015-10-22 23:11:40 +03:00
|
|
|
}
|
2001-03-15 06:06:47 +03:00
|
|
|
|
2015-10-22 23:11:40 +03:00
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(ctx);
|
2016-10-27 21:13:38 +03:00
|
|
|
rv = nsNSSDialogHelper::openDialog(
|
2011-07-15 14:31:34 +04:00
|
|
|
parent, "chrome://pippki/content/downloadcert.xul", argArray);
|
2015-10-22 23:11:40 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-27 00:50:54 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("importConfirmed"),
|
|
|
|
importConfirmed);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-27 00:50:54 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
*trust = nsIX509CertDB::UNTRUSTED;
|
|
|
|
if (!*importConfirmed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool trustForSSL = false;
|
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("trustForSSL"),
|
|
|
|
&trustForSSL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
bool trustForEmail = false;
|
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("trustForEmail"),
|
|
|
|
&trustForEmail);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-27 00:50:54 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
*trust |= trustForSSL ? nsIX509CertDB::TRUSTED_SSL : 0;
|
|
|
|
*trust |= trustForEmail ? nsIX509CertDB::TRUSTED_EMAIL : 0;
|
2001-02-27 00:50:54 +03:00
|
|
|
|
2016-10-27 21:13:38 +03:00
|
|
|
return NS_OK;
|
2001-02-27 00:50:54 +03:00
|
|
|
}
|
2001-03-07 22:24:12 +03:00
|
|
|
|
2001-04-03 05:06:17 +04:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 10:12:11 +03:00
|
|
|
nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor* ctx,
|
2016-07-26 15:16:58 +03:00
|
|
|
const nsACString& hostname, int32_t port,
|
|
|
|
const nsACString& organization,
|
|
|
|
const nsACString& issuerOrg, nsIArray* certList,
|
2016-06-24 10:12:11 +03:00
|
|
|
/*out*/ uint32_t* selectedIndex,
|
|
|
|
/*out*/ bool* certificateChosen) {
|
|
|
|
NS_ENSURE_ARG_POINTER(ctx);
|
2016-06-24 10:12:16 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(certList);
|
2016-06-24 10:12:11 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(selectedIndex);
|
|
|
|
NS_ENSURE_ARG_POINTER(certificateChosen);
|
|
|
|
|
|
|
|
*certificateChosen = false;
|
2001-04-03 05:06:17 +04:00
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
nsCOMPtr<nsIMutableArray> argArray = nsArrayBase::Create();
|
|
|
|
if (!argArray) {
|
2016-06-24 10:12:16 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-04-03 05:06:17 +04:00
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
nsCOMPtr<nsIWritableVariant> hostnameVariant = new nsVariant();
|
|
|
|
nsresult rv = hostnameVariant->SetAsAUTF8String(hostname);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(hostnameVariant);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-12-04 18:56:54 +03:00
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
nsCOMPtr<nsIWritableVariant> organizationVariant = new nsVariant();
|
|
|
|
rv = organizationVariant->SetAsAUTF8String(organization);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(organizationVariant);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-03 05:06:17 +04:00
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
nsCOMPtr<nsIWritableVariant> issuerOrgVariant = new nsVariant();
|
|
|
|
rv = issuerOrgVariant->SetAsAUTF8String(issuerOrg);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(issuerOrgVariant);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2001-04-03 05:06:17 +04:00
|
|
|
}
|
2016-10-23 07:57:41 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWritableVariant> portVariant = new nsVariant();
|
|
|
|
rv = portVariant->SetAsInt32(port);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(portVariant);
|
2016-07-26 15:16:58 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(certList);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2001-08-14 04:01:12 +04:00
|
|
|
}
|
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> retVals = new nsHashPropertyBag();
|
2017-10-21 17:53:02 +03:00
|
|
|
rv = argArray->AppendElement(retVals);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-03 05:06:17 +04:00
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
rv = nsNSSDialogHelper::openDialog(
|
|
|
|
nullptr, "chrome://pippki/content/clientauthask.xul", argArray);
|
2016-06-24 10:12:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-03 05:06:17 +04:00
|
|
|
|
2009-05-21 02:21:51 +04:00
|
|
|
nsCOMPtr<nsIClientAuthUserDecision> extraResult = do_QueryInterface(ctx);
|
|
|
|
if (extraResult) {
|
2016-10-23 07:57:41 +03:00
|
|
|
bool rememberSelection = false;
|
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("rememberSelection"),
|
|
|
|
&rememberSelection);
|
2009-05-21 02:21:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2016-10-23 07:57:41 +03:00
|
|
|
extraResult->SetRememberClientAuthCertificate(rememberSelection);
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-23 07:57:41 +03:00
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("certChosen"),
|
|
|
|
certificateChosen);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-06-24 10:12:11 +03:00
|
|
|
if (*certificateChosen) {
|
2016-10-23 07:57:41 +03:00
|
|
|
rv = retVals->GetPropertyAsUint32(NS_LITERAL_STRING("selectedIndex"),
|
|
|
|
selectedIndex);
|
2016-06-24 10:12:11 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-03 05:06:17 +04:00
|
|
|
}
|
2016-06-24 10:12:11 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-04-03 05:06:17 +04:00
|
|
|
}
|
|
|
|
|
2016-11-04 20:23:35 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor* ctx,
|
|
|
|
/*out*/ nsAString& password,
|
|
|
|
/*out*/ bool* confirmedPassword) {
|
|
|
|
// |ctx| is allowed to be null.
|
|
|
|
NS_ENSURE_ARG(confirmedPassword);
|
|
|
|
|
2001-03-20 21:00:44 +03:00
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(ctx);
|
2016-11-04 20:23:35 +03:00
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> retVals = new nsHashPropertyBag();
|
|
|
|
nsresult rv = nsNSSDialogHelper::openDialog(
|
2001-03-20 21:00:44 +03:00
|
|
|
parent, "chrome://pippki/content/setp12password.xul", retVals);
|
2016-11-04 20:23:35 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2001-03-20 21:00:44 +03:00
|
|
|
}
|
2016-11-04 20:23:35 +03:00
|
|
|
|
|
|
|
rv = retVals->GetPropertyAsBool(NS_LITERAL_STRING("confirmedPassword"),
|
|
|
|
confirmedPassword);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*confirmedPassword) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVals->GetPropertyAsAString(NS_LITERAL_STRING("password"), password);
|
2001-03-20 21:00:44 +03:00
|
|
|
}
|
|
|
|
|
2015-02-05 05:28:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor* ctx,
|
|
|
|
nsAString& _password, bool* _retval) {
|
|
|
|
*_retval = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPromptService> promptSvc(
|
|
|
|
do_GetService(NS_PROMPTSERVICE_CONTRACTID));
|
|
|
|
if (!promptSvc) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString msg;
|
|
|
|
nsresult rv =
|
2017-08-04 07:40:52 +03:00
|
|
|
mPIPStringBundle->GetStringFromName("getPKCS12FilePasswordMessage", msg);
|
2015-02-05 05:28:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-20 21:00:44 +03:00
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(ctx);
|
2015-02-05 05:28:00 +03:00
|
|
|
bool ignored = false;
|
|
|
|
char16_t* pwTemp = nullptr;
|
|
|
|
rv = promptSvc->PromptPassword(parent, nullptr, msg.get(), &pwTemp, nullptr,
|
|
|
|
&ignored, _retval);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-11-14 03:50:02 +03:00
|
|
|
if (*_retval) {
|
2015-02-05 05:28:00 +03:00
|
|
|
_password.Assign(pwTemp);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(pwTemp);
|
2001-03-20 21:00:44 +03:00
|
|
|
}
|
2015-02-05 05:28:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-03-20 21:00:44 +03:00
|
|
|
}
|
|
|
|
|
2001-08-16 03:27:42 +04:00
|
|
|
NS_IMETHODIMP
|
2017-07-06 15:00:35 +03:00
|
|
|
nsNSSDialogs::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor* aCtx,
|
|
|
|
nsIKeygenThread* runnable) {
|
2001-08-16 03:27:42 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(aCtx);
|
2001-08-16 03:27:42 +04:00
|
|
|
|
|
|
|
rv = nsNSSDialogHelper::openDialog(
|
|
|
|
parent, "chrome://pippki/content/createCertInfo.xul", runnable);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-05-03 05:00:56 +04:00
|
|
|
NS_IMETHODIMP
|
2017-02-26 15:36:40 +03:00
|
|
|
nsNSSDialogs::ChooseToken(nsIInterfaceRequestor* /*aCtx*/,
|
|
|
|
const char16_t** aTokenList, uint32_t aCount,
|
|
|
|
/*out*/ nsAString& aTokenChosen,
|
|
|
|
/*out*/ bool* aCanceled) {
|
|
|
|
NS_ENSURE_ARG(aTokenList);
|
|
|
|
NS_ENSURE_ARG(aCanceled);
|
2001-05-03 05:00:56 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanceled = false;
|
2001-05-03 05:00:56 +04:00
|
|
|
|
2007-09-05 17:04:54 +04:00
|
|
|
nsCOMPtr<nsIDialogParamBlock> block =
|
|
|
|
do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
|
2001-05-03 05:00:56 +04:00
|
|
|
if (!block) return NS_ERROR_FAILURE;
|
|
|
|
|
2001-12-04 18:56:54 +03:00
|
|
|
block->SetNumberStrings(aCount);
|
|
|
|
|
2017-02-26 15:36:40 +03:00
|
|
|
nsresult rv;
|
|
|
|
for (uint32_t i = 0; i < aCount; i++) {
|
2002-09-24 00:17:16 +04:00
|
|
|
rv = block->SetString(i, aTokenList[i]);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-05-03 05:00:56 +04:00
|
|
|
}
|
|
|
|
|
2001-12-21 08:58:34 +03:00
|
|
|
rv = block->SetInt(0, aCount);
|
2001-05-03 05:00:56 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = nsNSSDialogHelper::openDialog(
|
2001-05-03 05:00:56 +04:00
|
|
|
nullptr, "chrome://pippki/content/choosetoken.xul", block);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t status;
|
2001-05-03 05:00:56 +04:00
|
|
|
|
2001-12-21 08:58:34 +03:00
|
|
|
rv = block->GetInt(0, &status);
|
2001-05-03 05:00:56 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2017-02-26 15:36:40 +03:00
|
|
|
*aCanceled = (status == 0);
|
2001-05-03 05:00:56 +04:00
|
|
|
if (!*aCanceled) {
|
|
|
|
// retrieve the nickname
|
2017-02-26 15:36:40 +03:00
|
|
|
rv = block->GetString(0, getter_Copies(aTokenChosen));
|
2001-05-03 05:00:56 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-12-05 10:34:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNSSDialogs::DisplayProtectedAuth(nsIInterfaceRequestor* aCtx,
|
|
|
|
nsIProtectedAuthThread* runnable) {
|
|
|
|
// We cannot use nsNSSDialogHelper here. We cannot allow close widget
|
|
|
|
// in the window because protected authentication is interruptible
|
|
|
|
// from user interface and changing nsNSSDialogHelper's static variable
|
|
|
|
// would not be thread-safe
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-12-05 10:34:55 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-12-05 10:34:55 +03:00
|
|
|
// Get the parent window for the dialog
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> parent = do_GetInterface(aCtx);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowWatcher> windowWatcher =
|
2007-12-05 10:34:55 +03:00
|
|
|
do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-07-15 14:31:34 +04:00
|
|
|
if (!parent) {
|
|
|
|
windowWatcher->GetActiveWindow(getter_AddRefs(parent));
|
2007-12-05 10:34:55 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> newWindow;
|
2007-12-05 10:34:55 +03:00
|
|
|
rv = windowWatcher->OpenWindow(
|
|
|
|
parent, "chrome://pippki/content/protectedAuth.xul", "_blank",
|
|
|
|
"centerscreen,chrome,modal,titlebar,close=no", runnable,
|
|
|
|
getter_AddRefs(newWindow));
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-12-05 10:34:55 +03:00
|
|
|
return rv;
|
|
|
|
}
|