1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 2001
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Terry Hayes <thayes@netscape.com>
25 : * Javier Delgadillo <javi@netscape.com>
26 : * Petr Kostka <petr.kostka@st.com>
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either the GNU General Public License Version 2 or later (the "GPL"), or
30 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the MPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the MPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : /*
43 : * Dialog services for PIP.
44 : */
45 : #include "nsCOMPtr.h"
46 : #include "nsString.h"
47 : #include "nsXPIDLString.h"
48 : #include "nsReadableUtils.h"
49 : #include "nsIDOMWindow.h"
50 : #include "nsIDialogParamBlock.h"
51 : #include "nsIComponentManager.h"
52 : #include "nsIServiceManager.h"
53 : #include "nsIStringBundle.h"
54 : #include "nsIInterfaceRequestor.h"
55 : #include "nsIInterfaceRequestorUtils.h"
56 : #include "nsIX509Cert.h"
57 : #include "nsIX509CertDB.h"
58 : #include "nsIDateTimeFormat.h"
59 : #include "nsDateTimeFormatCID.h"
60 : #include "nsPromiseFlatString.h"
61 :
62 : #include "nsNSSDialogs.h"
63 : #include "nsPKIParamBlock.h"
64 : #include "nsIKeygenThread.h"
65 : #include "nsIProtectedAuthThread.h"
66 : #include "nsNSSDialogHelper.h"
67 : #include "nsIWindowWatcher.h"
68 : #include "nsIX509CertValidity.h"
69 : #include "nsICRLInfo.h"
70 :
71 : #define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
72 :
73 : /* ==== */
74 :
75 0 : nsNSSDialogs::nsNSSDialogs()
76 : {
77 0 : }
78 :
79 0 : nsNSSDialogs::~nsNSSDialogs()
80 : {
81 0 : }
82 :
83 0 : NS_IMPL_THREADSAFE_ISUPPORTS8(nsNSSDialogs, nsITokenPasswordDialogs,
84 : nsICertificateDialogs,
85 : nsIClientAuthDialogs,
86 : nsICertPickDialogs,
87 : nsITokenDialogs,
88 : nsIDOMCryptoDialogs,
89 : nsIGeneratingKeypairInfoDialogs,
90 : nsISSLCertErrorDialog)
91 :
92 : nsresult
93 0 : nsNSSDialogs::Init()
94 : {
95 : nsresult rv;
96 :
97 : nsCOMPtr<nsIStringBundleService> service =
98 0 : do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
99 0 : if (NS_FAILED(rv)) return rv;
100 :
101 0 : rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
102 0 : getter_AddRefs(mPIPStringBundle));
103 0 : return rv;
104 : }
105 :
106 : nsresult
107 0 : nsNSSDialogs::SetPassword(nsIInterfaceRequestor *ctx,
108 : const PRUnichar *tokenName, bool* _canceled)
109 : {
110 : nsresult rv;
111 :
112 0 : *_canceled = false;
113 :
114 : // Get the parent window for the dialog
115 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
116 :
117 : nsCOMPtr<nsIDialogParamBlock> block =
118 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
119 0 : if (!block) return NS_ERROR_FAILURE;
120 :
121 : // void ChangePassword(in wstring tokenName, out int status);
122 0 : rv = block->SetString(1, tokenName);
123 0 : if (NS_FAILED(rv)) return rv;
124 :
125 : rv = nsNSSDialogHelper::openDialog(parent,
126 : "chrome://pippki/content/changepassword.xul",
127 0 : block);
128 :
129 0 : if (NS_FAILED(rv)) return rv;
130 :
131 : PRInt32 status;
132 :
133 0 : rv = block->GetInt(1, &status);
134 0 : if (NS_FAILED(rv)) return rv;
135 :
136 0 : *_canceled = (status == 0)?true:false;
137 :
138 0 : return rv;
139 : }
140 :
141 : nsresult
142 0 : nsNSSDialogs::GetPassword(nsIInterfaceRequestor *ctx,
143 : const PRUnichar *tokenName,
144 : PRUnichar **_password,
145 : bool* _canceled)
146 : {
147 : nsresult rv;
148 0 : *_canceled = false;
149 : // Get the parent window for the dialog
150 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
151 : nsCOMPtr<nsIDialogParamBlock> block =
152 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
153 0 : if (!block) return NS_ERROR_FAILURE;
154 : // Set the token name in the window
155 0 : rv = block->SetString(1, tokenName);
156 0 : if (NS_FAILED(rv)) return rv;
157 : // open up the window
158 : rv = nsNSSDialogHelper::openDialog(parent,
159 : "chrome://pippki/content/getpassword.xul",
160 0 : block);
161 0 : if (NS_FAILED(rv)) return rv;
162 : // see if user canceled
163 : PRInt32 status;
164 0 : rv = block->GetInt(1, &status);
165 0 : if (NS_FAILED(rv)) return rv;
166 0 : *_canceled = (status == 0) ? true : false;
167 0 : if (!*_canceled) {
168 : // retrieve the password
169 0 : rv = block->GetString(2, _password);
170 : }
171 0 : return rv;
172 : }
173 :
174 : NS_IMETHODIMP
175 0 : nsNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl)
176 : {
177 : nsresult rv;
178 :
179 : nsCOMPtr<nsIPKIParamBlock> block =
180 0 : do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID,&rv);
181 0 : if (NS_FAILED(rv))
182 0 : return rv;
183 :
184 0 : rv = block->SetISupportAtIndex(1, crl);
185 0 : if (NS_FAILED(rv))
186 0 : return rv;
187 :
188 : rv = nsNSSDialogHelper::openDialog(nsnull,
189 : "chrome://pippki/content/crlImportDialog.xul",
190 : block,
191 0 : false);
192 0 : return NS_OK;
193 : }
194 :
195 : NS_IMETHODIMP
196 0 : nsNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx,
197 : nsIX509Cert *cert,
198 : PRUint32 *_trust,
199 : bool *_retval)
200 : {
201 : nsresult rv;
202 :
203 0 : *_retval = true;
204 :
205 : // Get the parent window for the dialog
206 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
207 :
208 : nsCOMPtr<nsIPKIParamBlock> block =
209 0 : do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
210 0 : if (!block)
211 0 : return NS_ERROR_FAILURE;
212 :
213 0 : rv = block->SetISupportAtIndex(1, cert);
214 0 : if (NS_FAILED(rv))
215 0 : return rv;
216 :
217 : rv = nsNSSDialogHelper::openDialog(parent,
218 : "chrome://pippki/content/downloadcert.xul",
219 0 : block);
220 0 : if (NS_FAILED(rv)) return rv;
221 :
222 : PRInt32 status;
223 : PRInt32 ssl, email, objsign;
224 :
225 0 : nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
226 :
227 0 : rv = dlgParamBlock->GetInt(1, &status);
228 0 : if (NS_FAILED(rv)) return rv;
229 0 : rv = dlgParamBlock->GetInt(2, &ssl);
230 0 : if (NS_FAILED(rv)) return rv;
231 0 : rv = dlgParamBlock->GetInt(3, &email);
232 0 : if (NS_FAILED(rv)) return rv;
233 0 : rv = dlgParamBlock->GetInt(4, &objsign);
234 0 : if (NS_FAILED(rv)) return rv;
235 :
236 0 : *_trust = nsIX509CertDB::UNTRUSTED;
237 0 : *_trust |= (ssl) ? nsIX509CertDB::TRUSTED_SSL : 0;
238 0 : *_trust |= (email) ? nsIX509CertDB::TRUSTED_EMAIL : 0;
239 0 : *_trust |= (objsign) ? nsIX509CertDB::TRUSTED_OBJSIGN : 0;
240 :
241 0 : *_retval = (status == 0)?false:true;
242 :
243 0 : return rv;
244 : }
245 :
246 :
247 : NS_IMETHODIMP
248 0 : nsNSSDialogs::NotifyCACertExists(nsIInterfaceRequestor *ctx)
249 : {
250 : nsresult rv;
251 :
252 : // Get the parent window for the dialog
253 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
254 :
255 : nsCOMPtr<nsIDialogParamBlock> block =
256 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
257 0 : if (!block) return NS_ERROR_FAILURE;
258 :
259 :
260 : rv = nsNSSDialogHelper::openDialog(parent,
261 : "chrome://pippki/content/cacertexists.xul",
262 0 : block);
263 :
264 0 : return rv;
265 : }
266 :
267 :
268 : NS_IMETHODIMP
269 0 : nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor *ctx, const PRUnichar *cn, const PRUnichar *organization, const PRUnichar *issuer, const PRUnichar **certNickList, const PRUnichar **certDetailsList, PRUint32 count, PRInt32 *selectedIndex, bool *canceled)
270 : {
271 : nsresult rv;
272 : PRUint32 i;
273 :
274 0 : *canceled = false;
275 :
276 : // Get the parent window for the dialog
277 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
278 :
279 : nsCOMPtr<nsIDialogParamBlock> block =
280 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
281 0 : if (!block) return NS_ERROR_FAILURE;
282 :
283 0 : block->SetNumberStrings(4+count*2);
284 :
285 0 : rv = block->SetString(0, cn);
286 0 : if (NS_FAILED(rv)) return rv;
287 :
288 0 : rv = block->SetString(1, organization);
289 0 : if (NS_FAILED(rv)) return rv;
290 :
291 0 : rv = block->SetString(2, issuer);
292 0 : if (NS_FAILED(rv)) return rv;
293 :
294 0 : for (i = 0; i < count; i++) {
295 0 : rv = block->SetString(i+3, certNickList[i]);
296 0 : if (NS_FAILED(rv)) return rv;
297 : }
298 :
299 0 : for (i = 0; i < count; i++) {
300 0 : rv = block->SetString(i+count+3, certDetailsList[i]);
301 0 : if (NS_FAILED(rv)) return rv;
302 : }
303 :
304 0 : rv = block->SetInt(0, count);
305 0 : if (NS_FAILED(rv)) return rv;
306 :
307 : rv = nsNSSDialogHelper::openDialog(nsnull,
308 : "chrome://pippki/content/clientauthask.xul",
309 0 : block);
310 0 : if (NS_FAILED(rv)) return rv;
311 :
312 : PRInt32 status;
313 0 : rv = block->GetInt(0, &status);
314 0 : if (NS_FAILED(rv)) return rv;
315 :
316 0 : nsCOMPtr<nsIClientAuthUserDecision> extraResult = do_QueryInterface(ctx);
317 0 : if (extraResult) {
318 : PRInt32 rememberSelection;
319 0 : rv = block->GetInt(2, &rememberSelection);
320 0 : if (NS_SUCCEEDED(rv)) {
321 0 : extraResult->SetRememberClientAuthCertificate(rememberSelection!=0);
322 : }
323 : }
324 :
325 0 : *canceled = (status == 0)?true:false;
326 0 : if (!*canceled) {
327 : // retrieve the nickname
328 0 : rv = block->GetInt(1, selectedIndex);
329 : }
330 0 : return rv;
331 : }
332 :
333 :
334 : NS_IMETHODIMP
335 0 : nsNSSDialogs::PickCertificate(nsIInterfaceRequestor *ctx,
336 : const PRUnichar **certNickList,
337 : const PRUnichar **certDetailsList,
338 : PRUint32 count,
339 : PRInt32 *selectedIndex,
340 : bool *canceled)
341 : {
342 : nsresult rv;
343 : PRUint32 i;
344 :
345 0 : *canceled = false;
346 :
347 : // Get the parent window for the dialog
348 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
349 :
350 : nsCOMPtr<nsIDialogParamBlock> block =
351 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
352 0 : if (!block) return NS_ERROR_FAILURE;
353 :
354 0 : block->SetNumberStrings(1+count*2);
355 :
356 0 : for (i = 0; i < count; i++) {
357 0 : rv = block->SetString(i, certNickList[i]);
358 0 : if (NS_FAILED(rv)) return rv;
359 : }
360 :
361 0 : for (i = 0; i < count; i++) {
362 0 : rv = block->SetString(i+count, certDetailsList[i]);
363 0 : if (NS_FAILED(rv)) return rv;
364 : }
365 :
366 0 : rv = block->SetInt(0, count);
367 0 : if (NS_FAILED(rv)) return rv;
368 :
369 0 : rv = block->SetInt(1, *selectedIndex);
370 0 : if (NS_FAILED(rv)) return rv;
371 :
372 : rv = nsNSSDialogHelper::openDialog(nsnull,
373 : "chrome://pippki/content/certpicker.xul",
374 0 : block);
375 0 : if (NS_FAILED(rv)) return rv;
376 :
377 : PRInt32 status;
378 :
379 0 : rv = block->GetInt(0, &status);
380 0 : if (NS_FAILED(rv)) return rv;
381 :
382 0 : *canceled = (status == 0)?true:false;
383 0 : if (!*canceled) {
384 0 : rv = block->GetInt(1, selectedIndex);
385 : }
386 0 : return rv;
387 : }
388 :
389 :
390 : NS_IMETHODIMP
391 0 : nsNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
392 : nsAString &_password,
393 : bool *_retval)
394 : {
395 : nsresult rv;
396 0 : *_retval = true;
397 : // Get the parent window for the dialog
398 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
399 : nsCOMPtr<nsIDialogParamBlock> block =
400 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
401 0 : if (!block) return NS_ERROR_FAILURE;
402 : // open up the window
403 : rv = nsNSSDialogHelper::openDialog(parent,
404 : "chrome://pippki/content/setp12password.xul",
405 0 : block);
406 0 : if (NS_FAILED(rv)) return rv;
407 : // see if user canceled
408 : PRInt32 status;
409 0 : rv = block->GetInt(1, &status);
410 0 : if (NS_FAILED(rv)) return rv;
411 0 : *_retval = (status == 0) ? false : true;
412 0 : if (*_retval) {
413 : // retrieve the password
414 : PRUnichar *pw;
415 0 : rv = block->GetString(2, &pw);
416 0 : if (NS_SUCCEEDED(rv)) {
417 0 : _password = pw;
418 0 : nsMemory::Free(pw);
419 : }
420 : }
421 0 : return rv;
422 : }
423 :
424 : NS_IMETHODIMP
425 0 : nsNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
426 : nsAString &_password,
427 : bool *_retval)
428 : {
429 : nsresult rv;
430 0 : *_retval = true;
431 : // Get the parent window for the dialog
432 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
433 : nsCOMPtr<nsIDialogParamBlock> block =
434 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
435 0 : if (!block) return NS_ERROR_FAILURE;
436 : // open up the window
437 : rv = nsNSSDialogHelper::openDialog(parent,
438 : "chrome://pippki/content/getp12password.xul",
439 0 : block);
440 0 : if (NS_FAILED(rv)) return rv;
441 : // see if user canceled
442 : PRInt32 status;
443 0 : rv = block->GetInt(1, &status);
444 0 : if (NS_FAILED(rv)) return rv;
445 0 : *_retval = (status == 0) ? false : true;
446 0 : if (*_retval) {
447 : // retrieve the password
448 : PRUnichar *pw;
449 0 : rv = block->GetString(2, &pw);
450 0 : if (NS_SUCCEEDED(rv)) {
451 0 : _password = pw;
452 0 : nsMemory::Free(pw);
453 : }
454 : }
455 0 : return rv;
456 : }
457 :
458 : /* void viewCert (in nsIX509Cert cert); */
459 : NS_IMETHODIMP
460 0 : nsNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx,
461 : nsIX509Cert *cert)
462 : {
463 : nsresult rv;
464 :
465 : nsCOMPtr<nsIPKIParamBlock> block =
466 0 : do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
467 0 : if (!block)
468 0 : return NS_ERROR_FAILURE;
469 :
470 0 : rv = block->SetISupportAtIndex(1, cert);
471 0 : if (NS_FAILED(rv))
472 0 : return rv;
473 :
474 : // Get the parent window for the dialog
475 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx);
476 :
477 : rv = nsNSSDialogHelper::openDialog(parent,
478 : "chrome://pippki/content/certViewer.xul",
479 : block,
480 0 : false);
481 0 : return rv;
482 : }
483 :
484 : NS_IMETHODIMP
485 0 : nsNSSDialogs::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable)
486 : {
487 : nsresult rv;
488 :
489 : // Get the parent window for the dialog
490 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
491 :
492 : rv = nsNSSDialogHelper::openDialog(parent,
493 : "chrome://pippki/content/createCertInfo.xul",
494 0 : runnable);
495 0 : return rv;
496 : }
497 :
498 : NS_IMETHODIMP
499 0 : nsNSSDialogs::ChooseToken(nsIInterfaceRequestor *aCtx, const PRUnichar **aTokenList, PRUint32 aCount, PRUnichar **aTokenChosen, bool *aCanceled) {
500 : nsresult rv;
501 : PRUint32 i;
502 :
503 0 : *aCanceled = false;
504 :
505 : // Get the parent window for the dialog
506 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
507 :
508 : nsCOMPtr<nsIDialogParamBlock> block =
509 0 : do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
510 0 : if (!block) return NS_ERROR_FAILURE;
511 :
512 0 : block->SetNumberStrings(aCount);
513 :
514 0 : for (i = 0; i < aCount; i++) {
515 0 : rv = block->SetString(i, aTokenList[i]);
516 0 : if (NS_FAILED(rv)) return rv;
517 : }
518 :
519 0 : rv = block->SetInt(0, aCount);
520 0 : if (NS_FAILED(rv)) return rv;
521 :
522 : rv = nsNSSDialogHelper::openDialog(nsnull,
523 : "chrome://pippki/content/choosetoken.xul",
524 0 : block);
525 0 : if (NS_FAILED(rv)) return rv;
526 :
527 : PRInt32 status;
528 :
529 0 : rv = block->GetInt(0, &status);
530 0 : if (NS_FAILED(rv)) return rv;
531 :
532 0 : *aCanceled = (status == 0)?true:false;
533 0 : if (!*aCanceled) {
534 : // retrieve the nickname
535 0 : rv = block->GetString(0, aTokenChosen);
536 : }
537 0 : return rv;
538 : }
539 :
540 : /* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */
541 : NS_IMETHODIMP
542 0 : nsNSSDialogs::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, bool *_retval)
543 :
544 : {
545 0 : *_retval = false;
546 :
547 : nsresult rv;
548 :
549 : nsCOMPtr<nsIPKIParamBlock> block =
550 0 : do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
551 0 : if (!block)
552 0 : return NS_ERROR_FAILURE;
553 :
554 0 : rv = block->SetISupportAtIndex(1, escrowAuthority);
555 0 : if (NS_FAILED(rv))
556 0 : return rv;
557 :
558 : rv = nsNSSDialogHelper::openDialog(nsnull,
559 : "chrome://pippki/content/escrowWarn.xul",
560 0 : block);
561 :
562 0 : if (NS_FAILED(rv))
563 0 : return rv;
564 :
565 0 : PRInt32 status=0;
566 0 : nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
567 0 : rv = dlgParamBlock->GetInt(1, &status);
568 :
569 0 : if (status) {
570 0 : *_retval = true;
571 : }
572 0 : return rv;
573 : }
574 :
575 : NS_IMETHODIMP
576 0 : nsNSSDialogs::DisplayProtectedAuth(nsIInterfaceRequestor *aCtx, nsIProtectedAuthThread *runnable)
577 : {
578 : // We cannot use nsNSSDialogHelper here. We cannot allow close widget
579 : // in the window because protected authentication is interruptible
580 : // from user interface and changing nsNSSDialogHelper's static variable
581 : // would not be thread-safe
582 :
583 0 : nsresult rv = NS_ERROR_FAILURE;
584 :
585 : // Get the parent window for the dialog
586 0 : nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx);
587 :
588 : nsCOMPtr<nsIWindowWatcher> windowWatcher =
589 0 : do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
590 0 : if (NS_FAILED(rv))
591 0 : return rv;
592 :
593 0 : if (!parent) {
594 0 : windowWatcher->GetActiveWindow(getter_AddRefs(parent));
595 : }
596 :
597 0 : nsCOMPtr<nsIDOMWindow> newWindow;
598 0 : rv = windowWatcher->OpenWindow(parent,
599 : "chrome://pippki/content/protectedAuth.xul",
600 : "_blank",
601 : "centerscreen,chrome,modal,titlebar,close=no",
602 : runnable,
603 0 : getter_AddRefs(newWindow));
604 :
605 0 : return rv;
606 : }
607 :
608 : NS_IMETHODIMP
609 0 : nsNSSDialogs::ShowCertError(nsIInterfaceRequestor *ctx,
610 : nsISSLStatus *status,
611 : nsIX509Cert *cert,
612 : const nsAString & textErrorMessage,
613 : const nsAString & htmlErrorMessage,
614 : const nsACString & hostName,
615 : PRUint32 portNumber)
616 : {
617 : nsCOMPtr<nsIPKIParamBlock> block =
618 0 : do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID);
619 0 : if (!block)
620 0 : return NS_ERROR_OUT_OF_MEMORY;
621 :
622 0 : nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
623 :
624 : nsresult rv;
625 0 : rv = dialogBlock->SetInt(1, portNumber);
626 0 : if (NS_FAILED(rv))
627 0 : return rv;
628 :
629 0 : rv = dialogBlock->SetString(1, NS_ConvertUTF8toUTF16(hostName).get());
630 0 : if (NS_FAILED(rv))
631 0 : return rv;
632 :
633 0 : rv = dialogBlock->SetString(2, PromiseFlatString(textErrorMessage).get());
634 0 : if (NS_FAILED(rv))
635 0 : return rv;
636 :
637 0 : rv = block->SetISupportAtIndex(1, cert);
638 0 : if (NS_FAILED(rv))
639 0 : return rv;
640 :
641 : rv = nsNSSDialogHelper::openDialog(nsnull,
642 : "chrome://pippki/content/certerror.xul",
643 0 : block);
644 0 : return rv;
645 : }
|