galeon r8971 - in trunk: . mozilla



Author: philipl
Date: Sun Jul  6 20:25:23 2008
New Revision: 8971
URL: http://svn.gnome.org/viewvc/galeon?rev=8971&view=rev

Log:
2008-07-05  Mike Hommey <mh glandium org>

	* configure.in
	* mozilla/EphyPromptService.cpp
	* mozilla/EphyPromptService.h: Add back support
	for http authentication when built against
	xulrunner 1.9.



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/mozilla/EphyPromptService.cpp
   trunk/mozilla/EphyPromptService.h

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Sun Jul  6 20:25:23 2008
@@ -758,6 +758,14 @@
 	[AC_DEFINE([HAVE_NSIPASSWORD_H],[1],
 	[Define if nsIPassword.h exists])])
 
+dnl nsIPromptService2 is how http auth is done in 1.9
+AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/nsIPromptService2.h],
+	[AC_DEFINE([HAVE_NSIPROMPTSERVICE2_H],[1],
+	[Define if nsIPromptService2.h exists])])
+AC_CHECK_FILE([$MOZILLA_INCLUDE_ROOT/windowwatcher/nsIPromptService2.h],
+	[AC_DEFINE([HAVE_NSIPROMPTSERVICE2_H],[1],
+	[Define if nsIPromptService2.h exists])])
+
 dnl restore flags
 CXXFLAGS="$_SAVE_CXXFLAGS $MOZ_DEBUG_FLAGS"
 CPPFLAGS=$_SAVE_CPPFLAGS

Modified: trunk/mozilla/EphyPromptService.cpp
==============================================================================
--- trunk/mozilla/EphyPromptService.cpp	(original)
+++ trunk/mozilla/EphyPromptService.cpp	Sun Jul  6 20:25:23 2008
@@ -38,6 +38,24 @@
 #include "AutoEventQueue.h"
 #endif
 
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+#include <nsIAuthInformation.h>
+#include <nsIStringBundle.h>
+#include <nsServiceManagerUtils.h>
+/* That is ugly but I didn't find another way, except including
+ * NS_GetAuthHostPort */
+#define kNotFound -1
+NS_COM void AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest );
+#include <nsStringAPI.h>
+#include <nsIProxiedChannel.h>
+#include <nsIProxyInfo.h>
+#include <nsIIDNService.h>
+#include <nsNetCID.h>
+#include <nsIURI.h>
+#include <nsNetUtil.h>
+#include <nsPromptUtils.h>
+#endif
+
 #include "GaleonUtils.h"
 
 #include <glib.h>
@@ -624,7 +642,11 @@
 }
 
 /* FIXME: needs THREADSAFE? */
-#if HAVE_NSINONBLOCKINGALERTSERVICE_H
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+NS_IMPL_ISUPPORTS2 (EphyPromptService,
+		    nsIPromptService,
+		    nsIPromptService2)
+#elif HAVE_NSINONBLOCKINGALERTSERVICE_H
 NS_IMPL_ISUPPORTS2 (EphyPromptService,
 		    nsIPromptService,
 		    nsINonBlockingAlertService)
@@ -868,3 +890,146 @@
 }
 
 #endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */
+
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+static nsresult
+MakeDialogText(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
+               nsString& message)
+{
+  nsresult rv;
+  nsCOMPtr<nsIStringBundleService> bundleSvc =
+    do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIStringBundle> bundle;
+  rv = bundleSvc->CreateBundle("chrome://global/locale/prompts.properties",
+                               getter_AddRefs(bundle));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // figure out what message to display...
+  nsCAutoString host;
+  PRInt32 port;
+  NS_GetAuthHostPort(aChannel, aAuthInfo, PR_FALSE, host, &port);
+
+  nsAutoString displayHost;
+  CopyUTF8toUTF16(host, displayHost);
+
+  nsCOMPtr<nsIURI> uri;
+  aChannel->GetURI(getter_AddRefs(uri));
+
+  nsCAutoString scheme;
+  uri->GetScheme(scheme);
+
+  nsAutoString username;
+  aAuthInfo->GetUsername(username);
+
+  PRUint32 flags;
+  aAuthInfo->GetFlags(&flags);
+  PRBool proxyAuth = (flags & nsIAuthInformation::AUTH_PROXY) != 0;
+
+  nsAutoString realm;
+  aAuthInfo->GetRealm(realm);
+
+  // Append the port if it was specified
+  if (port != -1) {
+    displayHost.Append(PRUnichar(':'));
+    displayHost.AppendInt(port);
+  }
+
+  NS_NAMED_LITERAL_STRING(proxyText, "EnterLoginForProxy");
+  NS_NAMED_LITERAL_STRING(originText, "EnterLoginForRealm");
+  NS_NAMED_LITERAL_STRING(noRealmText, "EnterUserPasswordFor");
+  NS_NAMED_LITERAL_STRING(passwordText, "EnterPasswordFor");
+
+  const PRUnichar *text;
+  if (proxyAuth) {
+    text = proxyText.get();
+  } else {
+    text = originText.get();
+
+    // prepend "scheme://"
+    nsAutoString schemeU;
+    CopyASCIItoUTF16(scheme, schemeU);
+    schemeU.AppendLiteral("://");
+    displayHost.Insert(schemeU, 0);
+  }
+
+  const PRUnichar *strings[] = { realm.get(), displayHost.get() };
+  PRUint32 count = NS_ARRAY_LENGTH(strings);
+
+  if (flags & nsIAuthInformation::ONLY_PASSWORD) {
+    text = passwordText.get();
+    strings[0] = username.get();
+  } else if (!proxyAuth && realm.IsEmpty()) {
+    text = noRealmText.get();
+    count--;
+    strings[0] = strings[1];
+  }
+
+  rv = bundle->FormatStringFromName(text, strings, count, getter_Copies(message));
+  return rv;
+}
+
+NS_METHOD
+EphyPromptService::PromptAuth(nsIDOMWindow *aParent,
+                              nsIChannel *aChannel,
+                              PRUint32 level,
+                              nsIAuthInformation *authInfo,
+                              const PRUnichar *checkboxLabel,
+                              PRBool *checkValue,
+                              PRBool *retval)
+{
+  NS_ENSURE_ARG_POINTER (retval);
+  NS_ENSURE_ARG_POINTER (authInfo);
+
+  nsString message;
+  MakeDialogText(aChannel, authInfo, message);
+
+  nsAutoString defaultUser, defaultDomain, defaultPass;
+  authInfo->GetUsername(defaultUser);
+  authInfo->GetDomain(defaultDomain);
+  authInfo->GetPassword(defaultPass);
+
+  PRUint32 flags;
+  authInfo->GetFlags(&flags);
+
+  if ((flags & nsIAuthInformation::NEED_DOMAIN) && !defaultDomain.IsEmpty()) {
+    defaultDomain.Append(PRUnichar('\\'));
+    defaultUser.Insert(defaultDomain, 0);
+  }
+
+  // NOTE: Allocation failure is not fatal here (just default to empty string
+  // if allocation fails)
+  PRUnichar *user = ToNewUnicode(defaultUser),
+    *pass = ToNewUnicode(defaultPass);
+  nsresult rv;
+  if (flags & nsIAuthInformation::ONLY_PASSWORD) {
+    rv = PromptPassword(aParent, nsnull, message.get(),
+                        &pass, checkboxLabel,
+                        checkValue, retval);
+  } else {
+    rv = PromptUsernameAndPassword(aParent, nsnull, message.get(),
+                                   &user, &pass, checkboxLabel,
+                                   checkValue, retval);
+  }
+  nsString userStr(user);
+  nsString passStr(pass);
+  authInfo->SetUsername(userStr);
+  authInfo->SetPassword(passStr);
+
+  return rv;
+}
+
+NS_METHOD EphyPromptService::AsyncPromptAuth(nsIDOMWindow *aParent,
+                                             nsIChannel *aChannel,
+                                             nsIAuthPromptCallback *aCallback,
+                                             nsISupports *aContext,
+                                             PRUint32 level,
+                                             nsIAuthInformation *authInfo,
+                                             const PRUnichar *checkboxLabel,
+                                             PRBool *checkValue,
+                                             nsICancelable **retval)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+#endif

Modified: trunk/mozilla/EphyPromptService.h
==============================================================================
--- trunk/mozilla/EphyPromptService.h	(original)
+++ trunk/mozilla/EphyPromptService.h	Sun Jul  6 20:25:23 2008
@@ -20,7 +20,11 @@
 #ifndef EPHY_PROMPT_SERVICE_H
 #define EPHY_PROMPT_SERVICE_H
 
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+#include <nsIPromptService2.h>
+#else
 #include <nsIPromptService.h>
+#endif
 
 #if HAVE_NSINONBLOCKINGALERTSERVICE_H
 #include <nsINonBlockingAlertService.h>
@@ -33,7 +37,12 @@
 
 #define EPHY_PROMPT_SERVICE_CLASSNAME	"Epiphany Prompt Service"
 
-class EphyPromptService : public nsIPromptService
+class EphyPromptService :
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+			public nsIPromptService2
+#else
+			public nsIPromptService
+#endif
 #if HAVE_NSINONBLOCKINGALERTSERVICE_H
 			, public nsINonBlockingAlertService
 #endif
@@ -41,6 +50,9 @@
 public:
 	NS_DECL_ISUPPORTS
 	NS_DECL_NSIPROMPTSERVICE
+#ifdef HAVE_NSIPROMPTSERVICE2_H
+	NS_DECL_NSIPROMPTSERVICE2
+#endif
 #if HAVE_NSINONBLOCKINGALERTSERVICE_H
 	NS_DECL_NSINONBLOCKINGALERTSERVICE
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]