|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include "nsFormSigningDialog.h" |
|
6 #include "nsNSSDialogHelper.h" |
|
7 #include "nsCOMPtr.h" |
|
8 #include "nsIDialogParamBlock.h" |
|
9 #include "nsIComponentManager.h" |
|
10 #include "nsIServiceManager.h" |
|
11 #include "nsIInterfaceRequestor.h" |
|
12 #include "nsIInterfaceRequestorUtils.h" |
|
13 #include "nsLiteralString.h" |
|
14 #include "nsXPIDLString.h" |
|
15 |
|
16 nsFormSigningDialog::nsFormSigningDialog() |
|
17 { |
|
18 } |
|
19 |
|
20 nsFormSigningDialog::~nsFormSigningDialog() |
|
21 { |
|
22 } |
|
23 |
|
24 NS_IMPL_ISUPPORTS(nsFormSigningDialog, nsIFormSigningDialog) |
|
25 |
|
26 NS_IMETHODIMP |
|
27 nsFormSigningDialog::ConfirmSignText(nsIInterfaceRequestor *aContext, |
|
28 const nsAString &aHost, |
|
29 const nsAString &aSignText, |
|
30 const char16_t **aCertNickList, |
|
31 const char16_t **aCertDetailsList, |
|
32 uint32_t aCount, int32_t *aSelectedIndex, |
|
33 nsAString &aPassword, bool *aCanceled) |
|
34 { |
|
35 *aCanceled = true; |
|
36 |
|
37 // Get the parent window for the dialog |
|
38 nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aContext); |
|
39 |
|
40 nsresult rv; |
|
41 nsCOMPtr<nsIDialogParamBlock> block = |
|
42 do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &rv); |
|
43 NS_ENSURE_SUCCESS(rv, rv); |
|
44 |
|
45 block->SetNumberStrings(3 + aCount * 2); |
|
46 |
|
47 rv = block->SetString(0, PromiseFlatString(aHost).get()); |
|
48 NS_ENSURE_SUCCESS(rv, rv); |
|
49 |
|
50 rv = block->SetString(1, PromiseFlatString(aSignText).get()); |
|
51 NS_ENSURE_SUCCESS(rv, rv); |
|
52 |
|
53 uint32_t i; |
|
54 for (i = 0; i < aCount; ++i) { |
|
55 rv = block->SetString(2 + 2 * i, aCertNickList[i]); |
|
56 NS_ENSURE_SUCCESS(rv, rv); |
|
57 |
|
58 rv = block->SetString(2 + (2 * i + 1), aCertDetailsList[i]); |
|
59 NS_ENSURE_SUCCESS(rv, rv); |
|
60 } |
|
61 |
|
62 rv = block->SetInt(0, aCount); |
|
63 NS_ENSURE_SUCCESS(rv, rv); |
|
64 |
|
65 rv = nsNSSDialogHelper::openDialog(parent, |
|
66 "chrome://pippki/content/formsigning.xul", |
|
67 block); |
|
68 NS_ENSURE_SUCCESS(rv, rv); |
|
69 |
|
70 int32_t status; |
|
71 rv = block->GetInt(0, &status); |
|
72 NS_ENSURE_SUCCESS(rv, rv); |
|
73 |
|
74 if (status == 0) { |
|
75 *aCanceled = true; |
|
76 } |
|
77 else { |
|
78 *aCanceled = false; |
|
79 |
|
80 rv = block->GetInt(1, aSelectedIndex); |
|
81 NS_ENSURE_SUCCESS(rv, rv); |
|
82 |
|
83 nsXPIDLString pw; |
|
84 rv = block->GetString(0, getter_Copies(pw)); |
|
85 NS_ENSURE_SUCCESS(rv, rv); |
|
86 |
|
87 aPassword = pw; |
|
88 } |
|
89 |
|
90 return NS_OK; |
|
91 } |