Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
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"
16 nsFormSigningDialog::nsFormSigningDialog()
17 {
18 }
20 nsFormSigningDialog::~nsFormSigningDialog()
21 {
22 }
24 NS_IMPL_ISUPPORTS(nsFormSigningDialog, nsIFormSigningDialog)
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;
37 // Get the parent window for the dialog
38 nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aContext);
40 nsresult rv;
41 nsCOMPtr<nsIDialogParamBlock> block =
42 do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &rv);
43 NS_ENSURE_SUCCESS(rv, rv);
45 block->SetNumberStrings(3 + aCount * 2);
47 rv = block->SetString(0, PromiseFlatString(aHost).get());
48 NS_ENSURE_SUCCESS(rv, rv);
50 rv = block->SetString(1, PromiseFlatString(aSignText).get());
51 NS_ENSURE_SUCCESS(rv, rv);
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);
58 rv = block->SetString(2 + (2 * i + 1), aCertDetailsList[i]);
59 NS_ENSURE_SUCCESS(rv, rv);
60 }
62 rv = block->SetInt(0, aCount);
63 NS_ENSURE_SUCCESS(rv, rv);
65 rv = nsNSSDialogHelper::openDialog(parent,
66 "chrome://pippki/content/formsigning.xul",
67 block);
68 NS_ENSURE_SUCCESS(rv, rv);
70 int32_t status;
71 rv = block->GetInt(0, &status);
72 NS_ENSURE_SUCCESS(rv, rv);
74 if (status == 0) {
75 *aCanceled = true;
76 }
77 else {
78 *aCanceled = false;
80 rv = block->GetInt(1, aSelectedIndex);
81 NS_ENSURE_SUCCESS(rv, rv);
83 nsXPIDLString pw;
84 rv = block->GetString(0, getter_Copies(pw));
85 NS_ENSURE_SUCCESS(rv, rv);
87 aPassword = pw;
88 }
90 return NS_OK;
91 }