Lines 36-41
Link Here
|
36 |
* |
36 |
* |
37 |
* ***** END LICENSE BLOCK ***** */ |
37 |
* ***** END LICENSE BLOCK ***** */ |
38 |
|
38 |
|
|
|
39 |
#include "config.h" |
39 |
#include "GtkPromptService.h" |
40 |
#include "GtkPromptService.h" |
40 |
#include <nsIWindowWatcher.h> |
41 |
#include <nsIWindowWatcher.h> |
41 |
#include <nsIWebBrowserChrome.h> |
42 |
#include <nsIWebBrowserChrome.h> |
Lines 49-54
Link Here
|
49 |
#include <nsIDOMCharacterData.h> |
50 |
#include <nsIDOMCharacterData.h> |
50 |
#include <nsIDOMText.h> |
51 |
#include <nsIDOMText.h> |
51 |
#include <nsMemory.h> |
52 |
#include <nsMemory.h> |
|
|
53 |
#ifdef HAVE_GECKO_1_9 |
54 |
#include <nsIAuthInformation.h> |
55 |
#include <nsIStringBundle.h> |
56 |
#include <nsServiceManagerUtils.h> |
57 |
/* That is ugly but I didn't find another way, except including |
58 |
* NS_GetAuthHostPort */ |
59 |
#define kNotFound -1 |
60 |
NS_COM void AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest ); |
61 |
#include <nsStringAPI.h> |
62 |
#include <nsIProxiedChannel.h> |
63 |
#include <nsIProxyInfo.h> |
64 |
#include <nsIIDNService.h> |
65 |
#include <nsNetCID.h> |
66 |
#include <nsIURI.h> |
67 |
#include <nsNetUtil.h> |
68 |
#include <nsPromptUtils.h> |
69 |
#endif |
52 |
|
70 |
|
53 |
#include <glib/gi18n.h> |
71 |
#include <glib/gi18n.h> |
54 |
#include "kz-prompt-dialog.h" |
72 |
#include "kz-prompt-dialog.h" |
Lines 89-96
Link Here
|
89 |
{ |
107 |
{ |
90 |
} |
108 |
} |
91 |
|
109 |
|
92 |
|
110 |
#ifdef HAVE_GECKO_1_9 |
|
|
111 |
NS_IMPL_ISUPPORTS2(GtkPromptService, nsIPromptService, nsIPromptService2) |
112 |
#else |
93 |
NS_IMPL_ISUPPORTS1(GtkPromptService, nsIPromptService) |
113 |
NS_IMPL_ISUPPORTS1(GtkPromptService, nsIPromptService) |
|
|
114 |
#endif |
94 |
|
115 |
|
95 |
NS_IMETHODIMP |
116 |
NS_IMETHODIMP |
96 |
GtkPromptService::Alert(nsIDOMWindow* aParent, const PRUnichar* aDialogTitle, |
117 |
GtkPromptService::Alert(nsIDOMWindow* aParent, const PRUnichar* aDialogTitle, |
Lines 338-347
Link Here
|
338 |
KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent |
359 |
KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent |
339 |
(TYPE_PROMPT_USER_PASS, |
360 |
(TYPE_PROMPT_USER_PASS, |
340 |
GTK_WINDOW(GetGtkWindowForDOMWindow(aParent)))); |
361 |
GTK_WINDOW(GetGtkWindowForDOMWindow(aParent)))); |
|
|
362 |
#ifndef HAVE_GECKO_1_9 |
341 |
gchar *host = GetURIForDOMWindow(aParent); |
363 |
gchar *host = GetURIForDOMWindow(aParent); |
342 |
kz_prompt_dialog_set_host (prompt, host); |
364 |
kz_prompt_dialog_set_host (prompt, host); |
343 |
if (host) |
365 |
if (host) |
344 |
g_free(host); |
366 |
g_free(host); |
|
|
367 |
#endif |
345 |
kz_prompt_dialog_set_title(prompt, |
368 |
kz_prompt_dialog_set_title(prompt, |
346 |
aDialogTitle ? cTitle.get() : _("Prompt")); |
369 |
aDialogTitle ? cTitle.get() : _("Prompt")); |
347 |
kz_prompt_dialog_set_message_text(prompt, cText.get()); |
370 |
kz_prompt_dialog_set_message_text(prompt, cText.get()); |
Lines 391-400
Link Here
|
391 |
KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent |
414 |
KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent |
392 |
(TYPE_PROMPT_PASS, |
415 |
(TYPE_PROMPT_PASS, |
393 |
GTK_WINDOW(GetGtkWindowForDOMWindow(aParent)))); |
416 |
GTK_WINDOW(GetGtkWindowForDOMWindow(aParent)))); |
|
|
417 |
#ifndef HAVE_GECKO_1_9 |
394 |
gchar *host = GetURIForDOMWindow(aParent); |
418 |
gchar *host = GetURIForDOMWindow(aParent); |
395 |
kz_prompt_dialog_set_host (prompt, host); |
419 |
kz_prompt_dialog_set_host (prompt, host); |
396 |
if (host) |
420 |
if (host) |
397 |
g_free(host); |
421 |
g_free(host); |
|
|
422 |
#endif |
398 |
kz_prompt_dialog_set_title(prompt, |
423 |
kz_prompt_dialog_set_title(prompt, |
399 |
aDialogTitle ? cTitle.get() : _("Prompt")); |
424 |
aDialogTitle ? cTitle.get() : _("Prompt")); |
400 |
kz_prompt_dialog_set_message_text(prompt, cText.get()); |
425 |
kz_prompt_dialog_set_message_text(prompt, cText.get()); |
Lines 510-512
Link Here
|
510 |
NS_UTF16ToCString(uri, NS_CSTRING_ENCODING_UTF8, c_uri); |
535 |
NS_UTF16ToCString(uri, NS_CSTRING_ENCODING_UTF8, c_uri); |
511 |
return g_strdup(c_uri.get()); |
536 |
return g_strdup(c_uri.get()); |
512 |
} |
537 |
} |
|
|
538 |
|
539 |
#ifdef HAVE_GECKO_1_9 |
540 |
static nsresult |
541 |
MakeDialogText(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo, |
542 |
nsString& message) |
543 |
{ |
544 |
nsresult rv; |
545 |
nsCOMPtr<nsIStringBundleService> bundleSvc = |
546 |
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); |
547 |
NS_ENSURE_SUCCESS(rv, rv); |
548 |
|
549 |
nsCOMPtr<nsIStringBundle> bundle; |
550 |
rv = bundleSvc->CreateBundle("chrome://global/locale/prompts.properties", |
551 |
getter_AddRefs(bundle)); |
552 |
NS_ENSURE_SUCCESS(rv, rv); |
553 |
|
554 |
// figure out what message to display... |
555 |
nsCAutoString host; |
556 |
PRInt32 port; |
557 |
NS_GetAuthHostPort(aChannel, aAuthInfo, PR_FALSE, host, &port); |
558 |
|
559 |
nsAutoString displayHost; |
560 |
CopyUTF8toUTF16(host, displayHost); |
561 |
|
562 |
nsCOMPtr<nsIURI> uri; |
563 |
aChannel->GetURI(getter_AddRefs(uri)); |
564 |
|
565 |
nsCAutoString scheme; |
566 |
uri->GetScheme(scheme); |
567 |
|
568 |
nsAutoString username; |
569 |
aAuthInfo->GetUsername(username); |
570 |
|
571 |
PRUint32 flags; |
572 |
aAuthInfo->GetFlags(&flags); |
573 |
PRBool proxyAuth = (flags & nsIAuthInformation::AUTH_PROXY) != 0; |
574 |
|
575 |
nsAutoString realm; |
576 |
aAuthInfo->GetRealm(realm); |
577 |
|
578 |
// Append the port if it was specified |
579 |
if (port != -1) { |
580 |
displayHost.Append(PRUnichar(':')); |
581 |
displayHost.AppendInt(port); |
582 |
} |
583 |
|
584 |
NS_NAMED_LITERAL_STRING(proxyText, "EnterLoginForProxy"); |
585 |
NS_NAMED_LITERAL_STRING(originText, "EnterLoginForRealm"); |
586 |
NS_NAMED_LITERAL_STRING(noRealmText, "EnterUserPasswordFor"); |
587 |
NS_NAMED_LITERAL_STRING(passwordText, "EnterPasswordFor"); |
588 |
|
589 |
const PRUnichar *text; |
590 |
if (proxyAuth) { |
591 |
text = proxyText.get(); |
592 |
} else { |
593 |
text = originText.get(); |
594 |
|
595 |
// prepend "scheme://" |
596 |
nsAutoString schemeU; |
597 |
CopyASCIItoUTF16(scheme, schemeU); |
598 |
schemeU.AppendLiteral("://"); |
599 |
displayHost.Insert(schemeU, 0); |
600 |
} |
601 |
|
602 |
const PRUnichar *strings[] = { realm.get(), displayHost.get() }; |
603 |
PRUint32 count = NS_ARRAY_LENGTH(strings); |
604 |
|
605 |
if (flags & nsIAuthInformation::ONLY_PASSWORD) { |
606 |
text = passwordText.get(); |
607 |
strings[0] = username.get(); |
608 |
} else if (!proxyAuth && realm.IsEmpty()) { |
609 |
text = noRealmText.get(); |
610 |
count--; |
611 |
strings[0] = strings[1]; |
612 |
} |
613 |
|
614 |
rv = bundle->FormatStringFromName(text, strings, count, getter_Copies(message)); |
615 |
return rv; |
616 |
} |
617 |
|
618 |
NS_METHOD |
619 |
GtkPromptService::PromptAuth(nsIDOMWindow *aParent, |
620 |
nsIChannel *aChannel, |
621 |
PRUint32 level, |
622 |
nsIAuthInformation *authInfo, |
623 |
const PRUnichar *checkboxLabel, |
624 |
PRBool *checkValue, |
625 |
PRBool *retval) |
626 |
{ |
627 |
NS_ENSURE_ARG_POINTER (retval); |
628 |
NS_ENSURE_ARG_POINTER (authInfo); |
629 |
|
630 |
nsString message; |
631 |
MakeDialogText(aChannel, authInfo, message); |
632 |
|
633 |
nsAutoString defaultUser, defaultDomain, defaultPass; |
634 |
authInfo->GetUsername(defaultUser); |
635 |
authInfo->GetDomain(defaultDomain); |
636 |
authInfo->GetPassword(defaultPass); |
637 |
|
638 |
PRUint32 flags; |
639 |
authInfo->GetFlags(&flags); |
640 |
|
641 |
if ((flags & nsIAuthInformation::NEED_DOMAIN) && !defaultDomain.IsEmpty()) { |
642 |
defaultDomain.Append(PRUnichar('\\')); |
643 |
defaultUser.Insert(defaultDomain, 0); |
644 |
} |
645 |
|
646 |
// NOTE: Allocation failure is not fatal here (just default to empty string |
647 |
// if allocation fails) |
648 |
PRUnichar *user = ToNewUnicode(defaultUser), |
649 |
*pass = ToNewUnicode(defaultPass); |
650 |
nsresult rv; |
651 |
if (flags & nsIAuthInformation::ONLY_PASSWORD) |
652 |
rv = PromptPassword(aParent, nsnull, message.get(), |
653 |
&pass, checkboxLabel, |
654 |
checkValue, retval); |
655 |
else |
656 |
rv = PromptUsernameAndPassword(aParent, nsnull, message.get(), |
657 |
&user, &pass, checkboxLabel, |
658 |
checkValue, retval); |
659 |
|
660 |
nsString userStr(user); |
661 |
nsString passStr(pass); |
662 |
authInfo->SetUsername(userStr); |
663 |
authInfo->SetPassword(passStr); |
664 |
|
665 |
return rv; |
666 |
} |
667 |
|
668 |
NS_METHOD GtkPromptService::AsyncPromptAuth(nsIDOMWindow *aParent, |
669 |
nsIChannel *aChannel, |
670 |
nsIAuthPromptCallback *aCallback, |
671 |
nsISupports *aContext, |
672 |
PRUint32 level, |
673 |
nsIAuthInformation *authInfo, |
674 |
const PRUnichar *checkboxLabel, |
675 |
PRBool *checkValue, |
676 |
nsICancelable **retval) |
677 |
{ |
678 |
return NS_ERROR_NOT_IMPLEMENTED; |
679 |
} |
680 |
|
681 |
#endif |